()
| 20 | return this.lua |
| 21 | } |
| 22 | func NewLuaStae() *LuaRuntime { |
| 23 | vm := lua.NewState(lua.Options{ |
| 24 | CallStackSize: 4096, |
| 25 | RegistrySize: 4096, |
| 26 | SkipOpenLibs: true, |
| 27 | IncludeGoStackTrace: true, |
| 28 | }) |
| 29 | |
| 30 | std_libs := map[string]lua.LGFunction{ |
| 31 | lua.LoadLibName: lua.OpenPackage, |
| 32 | lua.BaseLibName: lua.OpenBase, |
| 33 | lua.TabLibName: lua.OpenTable, |
| 34 | lua.OsLibName: OpenOsRuntime, |
| 35 | lua.StringLibName: lua.OpenString, |
| 36 | lua.MathLibName: lua.OpenMath, |
| 37 | } |
| 38 | |
| 39 | for name, lib := range std_libs { |
| 40 | vm.Push(vm.NewFunction(lib)) |
| 41 | vm.Push(lua.LString(name)) |
| 42 | vm.Call(1, 0) |
| 43 | } |
| 44 | |
| 45 | vm.SetGlobal("print", vm.NewFunction(luaPrint)) |
| 46 | vm.SetGlobal("lua_unmarshal", vm.NewFunction(luaUnMarshal)) |
| 47 | vm.SetGlobal("lua_marshal", vm.NewFunction(luaMarshal)) |
| 48 | |
| 49 | runtime := &LuaRuntime{ |
| 50 | lua: vm, |
| 51 | } |
| 52 | return runtime |
| 53 | } |
| 54 | |
| 55 | func (this *LuaRuntime) DoFile(path string) { |
| 56 | if err := this.lua.DoFile(path); err != nil { |
nothing calls this directly
no test coverage detected
searching dependent graphs…