Java Code Examples for org.luaj.vm2.LuaValue#isnumber()
The following examples show how to use
org.luaj.vm2.LuaValue#isnumber() .
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: Utilities.java From Lukkit with MIT License | 6 votes |
/** * Gets the Java object from a LuaValue. * * @param value the LuaValue * @return the Java object */ public static Object getObjectFromLuavalue(LuaValue value) { if (value.istable()) { return convertTable(value.checktable()); } else if (value.isint()) { return value.checkint(); } else if (value.islong()) { return value.checklong(); } else if (value.isnumber()) { return value.checkdouble(); } else if (value.isstring()) { return value.checkjstring(); } else if (value.isboolean()) { return value.checkboolean(); } else if (value.isnil()) { return null; } else { return value.checkuserdata(); } }
Example 2
Source File: DimenUtil.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 5 votes |
/** * convert a value to px,返回给Android系统的必须是整数 * * @param value * @return */ public static int dpiToPx(LuaValue value) { if (value != null && value.isnumber()) { return (int) (value.optdouble(0.0f) * Constants.sScale + 0.5f);//向上取整数 } return 0; }
Example 3
Source File: DimenUtil.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 5 votes |
/** * convert a value to px,返回给Android系统的必须是整数 * * @param value * @return */ public static int dpiToPx(LuaValue value, int defaultValue) { if (value != null && value.isnumber()) { return (int) (value.optdouble(0.0f) * Constants.sScale + 0.5f);//向上取整数 } return defaultValue; }
Example 4
Source File: LuaSkinLoader.java From beatoraja with GNU General Public License v3.0 | 5 votes |
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; } }
Example 5
Source File: DebugLib.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 4 votes |
public Varargs invoke(Varargs args) { int a = 1; LuaThread thread = args.isthread(a) ? args.checkthread(a++) : globals.running; LuaValue func = args.arg(a++); String what = args.optjstring(a++, "flnStu"); DebugLib.CallStack callstack = callstack(thread); // find the stack info DebugLib.CallFrame frame; if (func.isnumber()) { frame = callstack.getCallFrame(func.toint()); if (frame == null) return NONE; func = frame.f; } else if (func.isfunction()) { frame = callstack.findCallFrame(func); } else { return argerror(a - 2, "function or level"); } // start a table DebugInfo ar = callstack.auxgetinfo(what, (LuaFunction) func, frame); LuaTable info = new LuaTable(); if (what.indexOf('S') >= 0) { info.set(WHAT, LUA); info.set(SOURCE, valueOf(ar.source)); info.set(SHORT_SRC, valueOf(ar.short_src)); info.set(LINEDEFINED, valueOf(ar.linedefined)); info.set(LASTLINEDEFINED, valueOf(ar.lastlinedefined)); } if (what.indexOf('l') >= 0) { info.set(CURRENTLINE, valueOf(ar.currentline)); } if (what.indexOf('u') >= 0) { info.set(NUPS, valueOf(ar.nups)); info.set(NPARAMS, valueOf(ar.nparams)); info.set(ISVARARG, ar.isvararg ? ONE : ZERO); } if (what.indexOf('n') >= 0) { info.set(NAME, LuaValue.valueOf(ar.name != null ? ar.name : "?")); info.set(NAMEWHAT, LuaValue.valueOf(ar.namewhat)); } if (what.indexOf('t') >= 0) { info.set(ISTAILCALL, ZERO); } if (what.indexOf('L') >= 0) { LuaTable lines = new LuaTable(); info.set(ACTIVELINES, lines); DebugLib.CallFrame cf; for (int l = 1; (cf = callstack.getCallFrame(l)) != null; ++l) if (cf.f == func) lines.insert(-1, valueOf(cf.currentline())); } if (what.indexOf('f') >= 0) { if (func != null) info.set(FUNC, func); } return info; }
Example 6
Source File: DimenUtil.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 4 votes |
public static Integer dpiToPx(LuaValue value, Integer defaultValue) { if (value != null && value.isnumber()) { return (int) (value.optdouble(0.0f) * Constants.sScale + 0.5f);//向上取整数 } return defaultValue; }
Example 7
Source File: DebugLib.java From XPrivacyLua with GNU General Public License v3.0 | 4 votes |
public Varargs invoke(Varargs args) { int a=1; LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running; LuaValue func = args.arg(a++); String what = args.optjstring(a++, "flnStu"); DebugLib.CallStack callstack = callstack(thread); // find the stack info DebugLib.CallFrame frame; if ( func.isnumber() ) { frame = callstack.getCallFrame(func.toint()); if (frame == null) return NONE; func = frame.f; } else if ( func.isfunction() ) { frame = callstack.findCallFrame(func); } else { return argerror(a-2, "function or level"); } // start a table DebugInfo ar = callstack.auxgetinfo(what, (LuaFunction) func, frame); LuaTable info = new LuaTable(); if (what.indexOf('S') >= 0) { info.set(WHAT, LUA); info.set(SOURCE, valueOf(ar.source)); info.set(SHORT_SRC, valueOf(ar.short_src)); info.set(LINEDEFINED, valueOf(ar.linedefined)); info.set(LASTLINEDEFINED, valueOf(ar.lastlinedefined)); } if (what.indexOf('l') >= 0) { info.set( CURRENTLINE, valueOf(ar.currentline) ); } if (what.indexOf('u') >= 0) { info.set(NUPS, valueOf(ar.nups)); info.set(NPARAMS, valueOf(ar.nparams)); info.set(ISVARARG, ar.isvararg? ONE: ZERO); } if (what.indexOf('n') >= 0) { info.set(NAME, LuaValue.valueOf(ar.name!=null? ar.name: "?")); info.set(NAMEWHAT, LuaValue.valueOf(ar.namewhat)); } if (what.indexOf('t') >= 0) { info.set(ISTAILCALL, ZERO); } if (what.indexOf('L') >= 0) { LuaTable lines = new LuaTable(); info.set(ACTIVELINES, lines); DebugLib.CallFrame cf; for (int l = 1; (cf=callstack.getCallFrame(l)) != null; ++l) if (cf.f == func) lines.insert(-1, valueOf(cf.currentline())); } if (what.indexOf('f') >= 0) { if (func != null) info.set( FUNC, func ); } return info; }
Example 8
Source File: DebugLib.java From HtmlNative with Apache License 2.0 | 4 votes |
public Varargs invoke(Varargs args) { int a=1; LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running; LuaValue func = args.arg(a++); String what = args.optjstring(a++, "flnStu"); DebugLib.CallStack callstack = callstack(thread); // find the stack info DebugLib.CallFrame frame; if ( func.isnumber() ) { frame = callstack.getCallFrame(func.toint()); if (frame == null) return NONE; func = frame.f; } else if ( func.isfunction() ) { frame = callstack.findCallFrame(func); } else { return argerror(a-2, "function or level"); } // start a table DebugInfo ar = callstack.auxgetinfo(what, (LuaFunction) func, frame); LuaTable info = new LuaTable(); if (what.indexOf('S') >= 0) { info.set(WHAT, LUA); info.set(SOURCE, valueOf(ar.source)); info.set(SHORT_SRC, valueOf(ar.short_src)); info.set(LINEDEFINED, valueOf(ar.linedefined)); info.set(LASTLINEDEFINED, valueOf(ar.lastlinedefined)); } if (what.indexOf('l') >= 0) { info.set( CURRENTLINE, valueOf(ar.currentline) ); } if (what.indexOf('u') >= 0) { info.set(NUPS, valueOf(ar.nups)); info.set(NPARAMS, valueOf(ar.nparams)); info.set(ISVARARG, ar.isvararg? ONE: ZERO); } if (what.indexOf('n') >= 0) { info.set(NAME, LuaValue.valueOf(ar.name!=null? ar.name: "?")); info.set(NAMEWHAT, LuaValue.valueOf(ar.namewhat)); } if (what.indexOf('t') >= 0) { info.set(ISTAILCALL, ZERO); } if (what.indexOf('L') >= 0) { LuaTable lines = new LuaTable(); info.set(ACTIVELINES, lines); DebugLib.CallFrame cf; for (int l = 1; (cf=callstack.getCallFrame(l)) != null; ++l) if (cf.f == func) lines.insert(-1, valueOf(cf.currentline())); } if (what.indexOf('f') >= 0) { if (func != null) info.set( FUNC, func ); } return info; }
Example 9
Source File: DebugLib.java From luaj with MIT License | 4 votes |
public Varargs invoke(Varargs args) { int a=1; LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running; LuaValue func = args.arg(a++); String what = args.optjstring(a++, "flnStu"); DebugLib.CallStack callstack = callstack(thread); // find the stack info DebugLib.CallFrame frame; if ( func.isnumber() ) { frame = callstack.getCallFrame(func.toint()); if (frame == null) return NONE; func = frame.f; } else if ( func.isfunction() ) { frame = callstack.findCallFrame(func); } else { return argerror(a-2, "function or level"); } // start a table DebugInfo ar = callstack.auxgetinfo(what, (LuaFunction) func, frame); LuaTable info = new LuaTable(); if (what.indexOf('S') >= 0) { info.set(WHAT, LUA); info.set(SOURCE, valueOf(ar.source)); info.set(SHORT_SRC, valueOf(ar.short_src)); info.set(LINEDEFINED, valueOf(ar.linedefined)); info.set(LASTLINEDEFINED, valueOf(ar.lastlinedefined)); } if (what.indexOf('l') >= 0) { info.set( CURRENTLINE, valueOf(ar.currentline) ); } if (what.indexOf('u') >= 0) { info.set(NUPS, valueOf(ar.nups)); info.set(NPARAMS, valueOf(ar.nparams)); info.set(ISVARARG, ar.isvararg? ONE: ZERO); } if (what.indexOf('n') >= 0) { info.set(NAME, LuaValue.valueOf(ar.name!=null? ar.name: "?")); info.set(NAMEWHAT, LuaValue.valueOf(ar.namewhat)); } if (what.indexOf('t') >= 0) { info.set(ISTAILCALL, ZERO); } if (what.indexOf('L') >= 0) { LuaTable lines = new LuaTable(); info.set(ACTIVELINES, lines); DebugLib.CallFrame cf; for (int l = 1; (cf=callstack.getCallFrame(l)) != null; ++l) if (cf.f == func) lines.insert(-1, valueOf(cf.currentline())); } if (what.indexOf('f') >= 0) { if (func != null) info.set( FUNC, func ); } return info; }