plugin.lua 代码 localTestLib =require("test")functionPluginTest(param)print(param)print("coming PluginTest") TestLib.CallTestFunc()return"I'm coming lua!"end test.lua 代码 justTest = {}functionjustTest.CallTestFunc()print("coming justTest.CallTestFunc")end-- 一定要 return, 否则不生效retur...
main.lua 的内容: localm =require("myModule") m.MyAdd(10,20)print(m.name) 运行main.go 得到执行结果: comingcustomMyAdd1020testName 3.3 Go 调用 lua 中的代码 lua 中的代码 functionTestGoCallLua(x, y)returnx+y, x*yend go 中的代码 funcTestTestGoCallLua(L *lua.LState){ err := L.Cal...
main.lua local m = require("mymodule") m.myfunc() print(m.name)
} main.lua local m = require("mymodule") m.myfunc() print(m.name)版权声明:本文为hzqghost原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/hzqghost/article/details/122819439智能推荐虚拟...
local m = require("mymodule") m.myfunc() print(m.name) Calling Lua from Go L := lua.NewState() defer L.Close() if err := L.DoFile("double.lua"); err != nil { panic(err) } if err := L.CallByParam(lua.P{ Fn: L.GetGlobal("double"), NRet: 1, Protect: true, }, ...
Using the various OpenXXX(L *LState) int functions you can open only those libraries that you require, for an example see below. Options.IncludeGoStackTrace bool(default false) By default, GopherLua does not show Go stack traces when panics occur. You can get Go stack traces by setting th...
localTestLib =require("test")functionPluginTest(param)print(param)print("coming PluginTest") TestLib.CallTestFunc()return"I'm coming lua!"end test.lua 代码 justTest = {}functionjustTest.CallTestFunc()print("coming justTest.CallTestFunc")end-- 一定要 return, 否则不生效 return justTest ...
Available add-ons Advanced Security Enterprise-grade security features GitHub Copilot Enterprise-grade AI features Premium Support Enterprise-grade 24/7 support Pricing Search or jump to... Search code, repositories, users, issues, pull requests... Provide feedback We read every piece of ...
加载模块,在lua中一般是用require函数,但是我们的脚本实际是存储在mysql中,而require是读取本地文件系统或调用用户提前注册的加载器实现加载模块的,实际上我们也不必要设计一个加载器, 我们可以在lua中设置一个global变量,变量名就用模块名,变量内容就是脚本返回的_M table对象,需要用到这个对象,就用lua.GetGlobal(...
通过会存在require的包找不到的问题,这就需要我们在lua脚本中设置package.path 在golang中定义GetLuaPath()方法,并设置到lua虚拟机中 funcGetLuaPath(L *lua.LState)int{// 绝对路径L.Push(lua.LString(tconfig.ProjectDir +"/scripts/lua"))return1}// 给虚拟机添加GetLuaPath方法L.SetGlobal("GetLuaPath...