Search in sources :

Example 11 with Globals

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));
}
Also used : Globals(org.luaj.vm2.Globals) LuaValue(org.luaj.vm2.LuaValue)

Example 12 with Globals

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);
}
Also used : Prototype(org.luaj.vm2.Prototype) LuaClosure(org.luaj.vm2.LuaClosure) LuaString(org.luaj.vm2.LuaString)

Example 13 with Globals

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);
}
Also used : Prototype(org.luaj.vm2.Prototype) LuaClosure(org.luaj.vm2.LuaClosure)

Example 14 with Globals

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);
    }
}
Also used : Globals(org.luaj.vm2.Globals) LuaView(com.taobao.luaview.global.LuaView)

Example 15 with Globals

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;
    }
}
Also used : Globals(org.luaj.vm2.Globals)

Aggregations

Globals (org.luaj.vm2.Globals)9 LuaTable (org.luaj.vm2.LuaTable)5 LuaValue (org.luaj.vm2.LuaValue)3 LuaClosure (org.luaj.vm2.LuaClosure)2 Prototype (org.luaj.vm2.Prototype)2 Bit32Lib (org.luaj.vm2.lib.Bit32Lib)2 CoroutineLib (org.luaj.vm2.lib.CoroutineLib)2 DebugLib (org.luaj.vm2.lib.DebugLib)2 PackageLib (org.luaj.vm2.lib.PackageLib)2 StringLib (org.luaj.vm2.lib.StringLib)2 TableLib (org.luaj.vm2.lib.TableLib)2 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 HorizontalScrollView (android.widget.HorizontalScrollView)1 LuaView (com.taobao.luaview.global.LuaView)1 UDLuaTable (com.taobao.luaview.userdata.base.UDLuaTable)1 UDView (com.taobao.luaview.userdata.ui.UDView)1 UDViewGroup (com.taobao.luaview.userdata.ui.UDViewGroup)1 LVViewGroup (com.taobao.luaview.view.LVViewGroup)1 ILVView (com.taobao.luaview.view.interfaces.ILVView)1