org.luaj.vm2.LuaFunction Java Examples

The following examples show how to use org.luaj.vm2.LuaFunction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DebugLib.java    From XPrivacyLua with GNU General Public License v3.0 6 votes vote down vote up
public void funcinfo(LuaFunction f) {
	if (f.isclosure()) {
		Prototype p = f.checkclosure().p;
		this.source = p.source != null ? p.source.tojstring() : "=?";
		this.linedefined = p.linedefined;
		this.lastlinedefined = p.lastlinedefined;
		this.what = (this.linedefined == 0) ? "main" : "Lua";
		this.short_src = p.shortsource();
	} else {
		this.source = "=[Java]";
		this.linedefined = -1;
		this.lastlinedefined = -1;
		this.what = "Java";
		this.short_src = f.name();
	}
}
 
Example #2
Source File: DebugLib.java    From luaj with MIT License 6 votes vote down vote up
public void funcinfo(LuaFunction f) {
	if (f.isclosure()) {
		Prototype p = f.checkclosure().p;
		this.source = p.source != null ? p.source.tojstring() : "=?";
		this.linedefined = p.linedefined;
		this.lastlinedefined = p.lastlinedefined;
		this.what = (this.linedefined == 0) ? "main" : "Lua";
		this.short_src = p.shortsource();
	} else {
		this.source = "=[Java]";
		this.linedefined = -1;
		this.lastlinedefined = -1;
		this.what = "Java";
		this.short_src = f.name();
	}
}
 
Example #3
Source File: DebugLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
public void funcinfo(LuaFunction f) {
    if (f.isclosure()) {
        Prototype p = f.checkclosure().p;
        this.source = p.source != null ? p.source.tojstring() : "=?";
        this.linedefined = p.linedefined;
        this.lastlinedefined = p.lastlinedefined;
        this.what = (this.linedefined == 0) ? "main" : "Lua";
        this.short_src = p.shortsource();
    } else {
        this.source = "=[Java]";
        this.linedefined = -1;
        this.lastlinedefined = -1;
        this.what = "Java";
        this.short_src = f.name();
    }
}
 
Example #4
Source File: DebugLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
public LuaValue call(LuaValue value, LuaValue table) {
    LuaValue mt = table.opttable(null);
    switch (value.type()) {
        case TNIL:
            LuaNil.s_metatable = mt;
            break;
        case TNUMBER:
            LuaNumber.s_metatable = mt;
            break;
        case TBOOLEAN:
            LuaBoolean.s_metatable = mt;
            break;
        case TSTRING:
            LuaString.s_metatable = mt;
            break;
        case TFUNCTION:
            LuaFunction.s_metatable = mt;
            break;
        case TTHREAD:
            LuaThread.s_metatable = mt;
            break;
        default:
            value.setmetatable(mt);
    }
    return value;
}
 
Example #5
Source File: LVHttpPlugin.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
private static Varargs startConnect(Varargs args, LVHttpBridge lvHttpBridge, RequestType requestType) {
    final int fixIndex = VenvyLVLibBinder.fixIndex(args);
    int requestId = -1;
    if (args.narg() > fixIndex) {
        String url = LuaUtil.getString(args, fixIndex + 1);
        LuaTable table = LuaUtil.getTable(args, fixIndex + 2);
        LuaFunction callback = LuaUtil.getFunction(args, fixIndex + 3);
        switch (requestType) {
            case GET:
                requestId = lvHttpBridge.get(url, table, callback);
                break;
            case POST:
                requestId = lvHttpBridge.post(url, table, callback);
                break;
            case PUT:
                requestId = lvHttpBridge.put(url, table, callback);
                break;
            case DELETE:
                requestId = lvHttpBridge.delete(url, table, callback);
                break;
        }
    }
    return LuaValue.valueOf(requestId);
}
 
Example #6
Source File: LVRecordPlugin.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Varargs invoke(Varargs args) {
    final int fixIndex = VenvyLVLibBinder.fixIndex(args);
    if (args.narg() > fixIndex) {
        if (mPlatform != null && mPlatform.getPlatformRecordInterface() != null) {
            final LuaFunction callback = LuaUtil.getFunction(args, fixIndex + 1);
            if (callback == null) {
                return LuaValue.NIL;
            }
            mPlatform.getPlatformRecordInterface().endRecord(new IPlatformRecordInterface.RecordCallback() {
                @Override
                public void onRecordResult(String filePath) {
                    LuaUtil.callFunction(callback, LuaValue.valueOf(filePath));
                }
            });
        }
    }
    return LuaValue.NIL;
}
 
Example #7
Source File: LVLoginPlugin.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Varargs invoke(Varargs args) {
    final int fixIndex = VenvyLVLibBinder.fixIndex(args);
    if (args.narg() > fixIndex) {
        if (mPlatform != null && mPlatform.getPlatformLoginInterface() != null) {
            final LuaFunction callback = LuaUtil.getFunction(args, fixIndex + 1);
            mPlatform.getPlatformLoginInterface().login(new IPlatformLoginInterface.LoginCallback() {
                @Override
                public void loginSuccess(PlatformUserInfo platformUserInfo) {
                    LuaUtil.callFunction(callback, JsonUtil.toLuaTable(platformUserInfo.toString()));
                }

                @Override
                public void loginError(LoginException loginException) {
                    LuaUtil.callFunction(callback, LuaValue.NIL);
                }
            });
        }
    }
    return LuaValue.NIL;
}
 
Example #8
Source File: LVHttpBridge.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
public void upload(final String url, String filePath, final LuaFunction callback) {
    File file = new File(filePath);
    if (!file.exists()) {
        LuaUtil.callFunction(callback, LuaValue.NIL);
        return;
    }

    final PostFormRequest.FileInfo fileInfo = new PostFormRequest.FileInfo();
    fileInfo.file = file;
    fileInfo.fileName = filePath;
    fileInfo.name = "file";
    if (mUploadHelper == null) {
        mUploadHelper = new FileUploadHelper();
    }
    mUploadHelper.uploadAsync(PostFormRequest.upload(fileInfo, url), new FileUploadHelper.IUploadListener() {

        @Override
        public void uploadComplete(String data) {
            VenvyLog.i("--图片上传结果--" + data);
            LuaUtil.callFunction(callback, TextUtils.isEmpty(data) ? LuaValue.NIL : LuaValue.valueOf(data));
        }
    });
}
 
Example #9
Source File: VenvyUDWebView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
public String callJS(String jsMethod, final LuaFunction callback) {
    IVenvyWebView webView;
    if (getView() == null || (webView = this.getView().getWebView()) == null) {
        return "";
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        webView.evaluateJavascript(jsMethod, new ValueCallback<String>() {
            /**
             *
             * @param value  js的函数执行的返回值
             */
            @Override
            public void onReceiveValue(String value) {
                LuaValue luaValue = LuaValue.valueOf(value);
                LuaUtil.callFunction(callback, luaValue);
            }
        });
    } else {
        webView.loadUrl(jsMethod);
    }


    return "";
}
 
Example #10
Source File: DebugLib.java    From HtmlNative with Apache License 2.0 6 votes vote down vote up
public void funcinfo(LuaFunction f) {
	if (f.isclosure()) {
		Prototype p = f.checkclosure().p;
		this.source = p.source != null ? p.source.tojstring() : "=?";
		this.linedefined = p.linedefined;
		this.lastlinedefined = p.lastlinedefined;
		this.what = (this.linedefined == 0) ? "main" : "Lua";
		this.short_src = p.shortsource();
	} else {
		this.source = "=[Java]";
		this.linedefined = -1;
		this.lastlinedefined = -1;
		this.what = "Java";
		this.short_src = f.name();
	}
}
 
Example #11
Source File: VenvyUDHttpRequestCallback.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
private LuaValue startConnect(Varargs args, LVHttpBridge lvHttpBridge, RequestType requestType) {
    final int fixIndex = VenvyLVLibBinder.fixIndex(args);
    int requestId = -1;
    if (args.narg() > fixIndex) {
        String url = LuaUtil.getString(args, 2);
        LuaTable table = LuaUtil.getTable(args, 3);
        LuaFunction callback = LuaUtil.getFunction(args, 4);
        switch (requestType) {
            case GET:
                requestId = lvHttpBridge.get(url, table, callback);
                break;
            case POST:
                requestId = lvHttpBridge.post(url, table, callback);
                break;
            case PUT:
                requestId = lvHttpBridge.put(url, table, callback);
                break;
            case DELETE:
                requestId = lvHttpBridge.delete(url, table, callback);
                break;
        }
    }
    return LuaValue.valueOf(requestId);
}
 
Example #12
Source File: LuaModInstance.java    From Cubes with MIT License 6 votes vote down vote up
public LuaModInstance(String name, FileHandle file, AssetManager assetManager, Map<String, FileHandle> luaFiles, FileHandle luaFolder) {
  super(name, file, assetManager);
  this.luaFiles = luaFiles;
  this.luaFolder = luaFolder;
  this.modStates = new ArrayList<ModState>();

  this.globals = CubesLua.globals(); // each mod has its own globals
  this.luaModEvent = new Multimap<ModState, LuaFunction>();
  this.globalEventListeners = new ArrayList<LuaEventListener>();
  this.clientEventListeners = new ArrayList<LuaEventListener>();
  this.serverEventListeners = new ArrayList<LuaEventListener>();

  int length = Integer.MAX_VALUE;
  String current = luaFiles.keySet().iterator().next();
  for (Entry<String, FileHandle> entry : luaFiles.entrySet()) {
    String s = entry.getKey();
    if (s.toLowerCase().contains("init") && s.length() < length) {
      length = s.length();
      current = s;
    }
  }
  initFile = name + "|" + current;
  Log.debug("Using '" + initFile + "' as init file");
}
 
Example #13
Source File: JavaLoader.java    From luaj with MIT License 5 votes vote down vote up
public LuaFunction load(String classname, LuaValue env) {
	try {
		Class c = loadClass( classname );
		LuaFunction v = (LuaFunction) c.newInstance();
		v.initupvalue1(env);
		return v;
	} catch ( Exception e ) {
		e.printStackTrace();
		throw new IllegalStateException("bad class gen: "+e);
	}
}
 
Example #14
Source File: UDViewGroup.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 提供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;
}
 
Example #15
Source File: DebugLib.java    From luaj with MIT License 5 votes vote down vote up
public LuaValue call(LuaValue value, LuaValue table) {
	LuaValue mt = table.opttable(null);
	switch ( value.type() ) {
		case TNIL:      LuaNil.s_metatable      = mt; break;
		case TNUMBER:   LuaNumber.s_metatable   = mt; break;
		case TBOOLEAN:  LuaBoolean.s_metatable  = mt; break;
		case TSTRING:   LuaString.s_metatable   = mt; break;
		case TFUNCTION: LuaFunction.s_metatable = mt; break;
		case TTHREAD:   LuaThread.s_metatable   = mt; break;
		default: value.setmetatable( mt );
	}
	return value;
}
 
Example #16
Source File: UIImageViewMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public LuaValue setImage(U view, Varargs varargs) {
    if (varargs.isstring(2)) {
        final String url = varargs.optjstring(2, null);
        final LuaFunction callback = varargs.optfunction(3, null);
        return view.setImageUrl(url, callback);
    } else if (varargs.arg(2) instanceof UDData) {//data
        final UDData data = (UDData) varargs.arg(2);
        return view.setImageBytes(data != null ? Base64.decode(data.bytes(), Base64.NO_WRAP) : null);
    }
    return view;
}
 
Example #17
Source File: DebugLib.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
public LuaValue call(LuaValue value, LuaValue table) {
	LuaValue mt = table.opttable(null);
	switch ( value.type() ) {
		case TNIL:      LuaNil.s_metatable      = mt; break;
		case TNUMBER:   LuaNumber.s_metatable   = mt; break;
		case TBOOLEAN:  LuaBoolean.s_metatable  = mt; break;
		case TSTRING:   LuaString.s_metatable   = mt; break;
		case TFUNCTION: LuaFunction.s_metatable = mt; break;
		case TTHREAD:   LuaThread.s_metatable   = mt; break;
		default: value.setmetatable( mt );
	}
	return value;
}
 
Example #18
Source File: UIImageViewMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public LuaValue setPlaceHolderImage(U view, Varargs varargs) {
    if (varargs.isstring(2)) {
        final String url = varargs.optjstring(2, null);
        final LuaFunction callback = varargs.optfunction(3, null);
        return view.setPlaceHolderImage(url, callback);
    } else if (varargs.arg(2) instanceof UDData) {//data
        final UDData data = (UDData) varargs.arg(2);
        return view.setPlaceHolderBytes(data != null ? Base64.decode(data.bytes(), Base64.NO_WRAP) : null);
    }
    return view;
}
 
Example #19
Source File: UDImageView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public UDImageView setPlaceHolderImage(final String placeHolderImage, final LuaFunction callback) {
    final T imageView = getView();
    if (imageView != null) {
        if (!TextUtils.isEmpty(placeHolderImage)) {
            imageView.setPlaceHolderImg(placeHolderImage);

            Drawable drawable = null;
            if (getLuaResourceFinder() != null) {
                drawable = getLuaResourceFinder().findDrawable(placeHolderImage);
                imageView.setPlaceHolderDrawable(drawable);
            }
        }
    }
    return this;
}
 
Example #20
Source File: VenvyAcrCloudMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public LuaValue acrRecordEnd(U target, Varargs args) {
    final int fixIndex = VenvyLVLibBinder.fixIndex(args);
    if (args.narg() > fixIndex) {
        final LuaFunction callback = LuaUtil.getFunction(args, fixIndex + 2);
        if (callback == null) {
            return LuaValue.NIL;
        }
        target.acrRecordEnd(callback);
    }
    return LuaValue.NIL;
}
 
Example #21
Source File: LVHttpPlugin.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Varargs invoke(Varargs args) {
    final int fixIndex = VenvyLVLibBinder.fixIndex(args);
    if (args.narg() > fixIndex) {
        String url = LuaUtil.getString(args, fixIndex + 1);
        String filePath = LuaUtil.getString(args, fixIndex + 2);
        LuaFunction callback = LuaUtil.getFunction(args, fixIndex + 3);
        httpBridge.upload(url, filePath, callback);

    }
    return LuaValue.NIL;
}
 
Example #22
Source File: VenvyAcrCloudMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public LuaValue acrRecognizeCallback(U target, Varargs varargs) {
    final LuaFunction callback = varargs.optfunction(2, null);
    if (callback != null && callback.isfunction()) {
        return target.setAcrCloudCallback(callback);
    }
    return LuaValue.NIL;
}
 
Example #23
Source File: VenvyKeyboardMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public LuaValue keyboardCallback(U target, Varargs varargs) {
    final LuaFunction callback = varargs.optfunction(2, null);
    if (callback != null && callback.isfunction()) {
        return target.setKeyboardCallback(callback);
    }
    return LuaValue.NIL;
}
 
Example #24
Source File: VenvyLVImageScannerDialog.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public void setCropImageResultListener(final LuaFunction luaFunction) {
    if (mImageScannerDialogLayout != null) {
        mImageScannerDialogLayout.mCropImageResultListener = new IWidgetClickListener<String>() {
            @Override
            public void onClick(@Nullable String imgPath) {
                if (luaFunction != null) {
                    LuaValue value = LuaValue.valueOf(imgPath);
                    LuaUtil.callFunction(luaFunction, value);
                }
                dismiss();
            }
        };
    }
}
 
Example #25
Source File: VenvyMqttMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public LuaValue mqttCallback(U target, Varargs varargs) {
    final LuaFunction callback = varargs.optfunction(2, null);
    if (callback != null && callback.isfunction()) {
        return target.setMqttCallback(callback);
    }
    return LuaValue.NIL;
}
 
Example #26
Source File: DebugLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public void onCall(LuaFunction f) {
    LuaThread t = globals.running;
    callstack().onCall(f);

    if (t.inhook) return;
    if (t.hookcall && t.hookfunc != null)
        callHook(CALL, NIL);
}
 
Example #27
Source File: VenvyUDHttpRequestCallback.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public LuaValue upload(Varargs varargs) {
    final int fixIndex = VenvyLVLibBinder.fixIndex(varargs);
    if (varargs.narg() > fixIndex) {
        String url = LuaUtil.getString(varargs, 2);
        String filePath = LuaUtil.getString(varargs, 3);
        LuaFunction callback = LuaUtil.getFunction(varargs, 4);
        httpBridge.upload(url, filePath, callback);
    }
    return LuaValue.NIL;
}
 
Example #28
Source File: LVImageScannerBridge.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public void show(final LuaFunction luaFunction) {
    if (mImageScannerDialog == null) {
        mImageScannerDialog = new VenvyLVImageScannerDialog(mContext);
    }
    mImageScannerDialog.show(new ImageScannerDialog.ShowImageDialogResult() {
        @Override
        public void successful() {
            mImageScannerDialog.setCropImageResultListener(luaFunction);
        }
    });
}
 
Example #29
Source File: LuaGeneration.java    From Cubes with MIT License 5 votes vote down vote up
public void constructor(@This Object o, @AllArguments Object[] objects) { // @Origin Constructor constructor,
  LuaValue value = delegations.get("__new__");
  if (value.isnil()) return;
  if (!value.isfunction()) throw new DynamicDelegationError("__new__ for " + o.getClass().getName() + " is a " + value.typename());
  LuaFunction function = value.checkfunction();
  LuaValue[] parameters = convertParamsToLua(o, objects);
  function.invoke(parameters);
}
 
Example #30
Source File: LuaSkinLoader.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
private static <T> T serializeLuaScript(LuaValue lv, Function<LuaFunction, T> asFunction, Function<String, T> asScript, Function<Integer, T> byId) {
	if (lv.isfunction()) {
		return asFunction.apply(lv.checkfunction());
	} else if (lv.isnumber() && byId != null) {
		return byId.apply(lv.toint());
	} else if (lv.isstring()) {
		return asScript.apply(lv.tojstring());
	} else {
		return null;
	}
}