Search in sources :

Example 1 with Globals

use of org.luaj.vm2.Globals in project LuaViewSDK by alibaba.

the class LuaView method create.

//---------------------------------------静态方法------------------------------------------------
/**
     * create a luaview
     *
     * @param context
     * @return
     */
public static LuaView create(final Context context) {
    //初始化
    init(context);
    //create globals
    final Globals globals = LuaViewManager.createGlobals();
    //设置metaTable
    return createLuaView(context, globals);
}
Also used : Globals(org.luaj.vm2.Globals)

Example 2 with Globals

use of org.luaj.vm2.Globals in project LuaViewSDK by alibaba.

the class LuaViewManager method createGlobalsAsync.

/**
     * 创建Globals
     * 根据是否用lua-to-java bytecode来处理(如果使用LuaJC的话则会使用库bcel 533k)
     *
     * @return
     */
public static Globals createGlobalsAsync() {
    if (sStaticGlobals != null) {
        synchronized (sStaticGlobals) {
            Globals result = sStaticGlobals;
            sStaticGlobals = null;
            return result;
        }
    } else {
        final Globals globals = new Globals();
        new SimpleTask<Globals>() {

            @Override
            public void doTask(Globals... params) {
                setupGlobals(params != null && params.length > 0 ? params[0] : null);
            }
        }.executeSerial(//TODO 这里放到serial线程中执行,而不是executeInPool中执行,为了保证后续的执行时序列
        globals);
        return globals;
    }
}
Also used : Globals(org.luaj.vm2.Globals)

Example 3 with Globals

use of org.luaj.vm2.Globals in project LuaViewSDK by alibaba.

the class UDViewGroup method children.

/**
     * 提供View的构造环境,注意,callback里面不能有异步操作,否则操作的时序上会混乱
     *
     * @param callback
     * @return
     */
public UDViewGroup children(LuaFunction callback) {
    if (getView() instanceof ViewGroup) {
        Globals globals = getGlobals();
        if (globals != null) {
            globals.pushContainer(getView());
            LuaUtil.callFunction(callback, this);
            globals.popContainer();
        }
    }
    return this;
}
Also used : Globals(org.luaj.vm2.Globals) ViewGroup(android.view.ViewGroup) ILVViewGroup(com.taobao.luaview.view.interfaces.ILVViewGroup)

Example 4 with Globals

use of org.luaj.vm2.Globals in project LuaViewSDK by alibaba.

the class GlobalsExtender method doLoad.

/**
     * 真正加载一个库
     *
     * @param globals
     * @param name
     * @return
     */
public LuaValue doLoad(final Globals globals, final String name) {
    if (mLazyLoadLibs != null && mLazyLoadLibs.containsKey(name)) {
        final LuaValue lib = mLazyLoadLibs.get(name);
        LuaValue result = globals.load(lib);
        mLazyLoadLibs.remove(name);
        return result;
    }
    return null;
}
Also used : LuaValue(org.luaj.vm2.LuaValue)

Example 5 with Globals

use of org.luaj.vm2.Globals in project LuaViewSDK by alibaba.

the class GlobalsExtender method doLoad.

/**
     * 真正地加载一个库
     *
     * @param globals
     * @param p
     */
public boolean doLoad(final Globals globals, Prototype p) {
    boolean isAnyLoaded = false;
    if (p != null && p.k != null && p.k.length > 0) {
        StringBuffer sb = new StringBuffer();
        for (LuaValue name : p.k) {
            if (LuaUtil.isString(name)) {
                sb.append(name).append(" ");
                isAnyLoaded = (doLoad(globals, name.checkjstring()) != null) || isAnyLoaded;
            }
        }
    }
    return isAnyLoaded;
}
Also used : LuaValue(org.luaj.vm2.LuaValue)

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