use of org.luaj.vm2.Globals in project LuaViewSDK by alibaba.
the class JsePlatform method luaMain.
/** Simple wrapper for invoking a lua function with command line arguments.
* The supplied function is first given a new Globals object,
* then the program is run with arguments.
*/
public static void luaMain(LuaValue mainChunk, String[] args) {
Globals g = standardGlobals();
int n = args.length;
LuaValue[] vargs = new LuaValue[args.length];
for (int i = 0; i < n; ++i) vargs[i] = LuaValue.valueOf(args[i]);
LuaValue arg = LuaValue.listOf(vargs);
arg.set("n", n);
g.set("arg", arg);
mainChunk.initupvalue1(g);
mainChunk.invoke(LuaValue.varargsOf(vargs));
}
use of org.luaj.vm2.Globals in project aerospike-client-java by aerospike.
the class LuaInstance method loadSystemPackage.
private void loadSystemPackage(ClassLoader resourceLoader, String packageName) {
String resourcePath = "udf/" + packageName + ".lua";
Prototype prototype = LuaCache.loadPackageFromResource(resourceLoader, resourcePath, packageName);
LuaClosure function = new LuaClosure(prototype, globals);
function.invoke();
loadedTable.set(packageName, LuaValue.TRUE);
}
use of org.luaj.vm2.Globals in project aerospike-client-java by aerospike.
the class LuaInstance method loadPackage.
public void loadPackage(Statement statement) {
if (loadedTable.get(statement.getPackageName()).toboolean()) {
return;
}
Prototype prototype;
if (statement.getResourceLoader() == null || statement.getResourcePath() == null) {
prototype = LuaCache.loadPackageFromFile(statement.getPackageName());
} else {
prototype = LuaCache.loadPackageFromResource(statement.getResourceLoader(), statement.getResourcePath(), statement.getPackageName());
}
LuaClosure function = new LuaClosure(prototype, globals);
function.invoke();
loadedTable.set(statement.getPackageName(), LuaValue.TRUE);
}
use of org.luaj.vm2.Globals in project LuaViewSDK by alibaba.
the class BaseCacheUserdata method cacheObject.
private void cacheObject() {
final Globals globals = getGlobals();
final LuaView luaView = globals != null ? globals.getLuaView() : null;
if (luaView != null) {
luaView.cacheObject(getClass(), this);
}
}
use of org.luaj.vm2.Globals in project LuaViewSDK by alibaba.
the class LuaViewManager method createGlobals.
/**
* 创建Globals
* 根据是否用lua-to-java bytecode来处理(如果使用LuaJC的话则会使用库bcel 533k)
*
* @return
*/
public static Globals createGlobals() {
if (sStaticGlobals != null) {
synchronized (sStaticGlobals) {
Globals result = sStaticGlobals;
sStaticGlobals = null;
return result;
}
} else {
//加载系统libs TODO 性能瓶颈
final Globals globals = LuaViewConfig.isOpenDebugger() ? JsePlatform.debugGlobals() : JsePlatform.standardGlobals();
if (LuaViewConfig.isUseLuaDC()) {
LuaDC.install(globals);
}
//加载用户lib TODO 性能瓶颈
loadLuaViewLibs(globals);
return globals;
}
}
Aggregations