-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlua.go
More file actions
43 lines (40 loc) · 917 Bytes
/
lua.go
File metadata and controls
43 lines (40 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package lua
// Call -- dofile(filePath) and call methodName on vm
func Call(filePath string, methodName string, args ...interface{}) (interface{}, error) {
callback := make(chan interface{})
defer close(callback)
ctx := &gLuaContext{
vmId: 0,
threadId: 0,
scriptPath: filePath,
methodName: methodName,
args: args,
callback: callback,
}
getCore().push(ctx)
Resume:
res := <-ctx.callback
switch res.(type) {
case error:
if res.(error).Error() == "LUA_YIELD" {
yctx, err := loadYieldContext(ctx.threadId)
if err != nil {
return nil, err
}
go func() {
res, err := callExternMethod(yctx.methodName, yctx.args...)
if err == nil {
ctx.args = []interface{}{res, nil}
} else {
ctx.args = []interface{}{res, err.Error()}
}
getCore().push(ctx)
}()
goto Resume
} else {
return nil, res.(error)
}
default:
return res, nil
}
}