Search in sources :

Example 1 with NewIndexFunction

use of com.taobao.luaview.fun.mapper.ui.NewIndexFunction in project LuaViewSDK by alibaba.

the class LuaViewManager method createMetatable.

// -----------------------------------------metatable--------------------------------------------
/**
 * create metatable for libs
 *
 * @return
 */
public static LuaTable createMetatable(Class<? extends LibFunction> libClass) {
    // get from cache
    LuaTable result = AppCache.getCache(CACHE_METATABLES).get(libClass);
    if (result == null) {
        LuaTable libTable = null;
        if (LuaViewConfig.isUseNoReflection()) {
            final List<String> methodNames = getMapperMethodNames(libClass);
            libTable = LuaViewManager.bind(libClass, methodNames);
        } else {
            final List<Method> methods = getMapperMethods(libClass);
            libTable = LuaViewManager.bindMethods(libClass, methods);
        }
        result = LuaValue.tableOf(new LuaValue[] { LuaValue.INDEX, libTable, LuaValue.NEWINDEX, new NewIndexFunction(libTable) });
        // update cache
        AppCache.getCache(CACHE_METATABLES).put(libClass, result);
    }
    return result;
}
Also used : NewIndexFunction(com.taobao.luaview.fun.mapper.ui.NewIndexFunction) LuaTable(org.luaj.vm2.LuaTable) Method(java.lang.reflect.Method) LuaValue(org.luaj.vm2.LuaValue)

Aggregations

NewIndexFunction (com.taobao.luaview.fun.mapper.ui.NewIndexFunction)1 Method (java.lang.reflect.Method)1 LuaTable (org.luaj.vm2.LuaTable)1 LuaValue (org.luaj.vm2.LuaValue)1