[英]LuaJ add lua function in Java
I am aware of this method: 我知道这种方法:
How can I add functions to _G that run java code using Luaj? 如何使用Luaj向_G添加运行Java代码的函数?
But that link lets you add functions such as math.abs(...)
. 但是,该链接使您可以添加诸如
math.abs(...)
函数。 I just want to add functions without libraries or having to use require
, you can just use myfunction()
right out of the box. 我只想添加没有库的函数或必须使用
require
,就可以直接使用myfunction()
。
How do I do this? 我该怎么做呢?
I found the answer in the LuaJ source: 我在LuaJ来源中找到了答案:
public LuaValue call(LuaValue modname, LuaValue env)
{
globals = env.checkglobals();
env.set("assert", new _assert());
env.set("collectgarbage", new collectgarbage());
env.set("dofile", new dofile());
....
return env;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.