Java Code Examples for org.luaj.vm2.LuaValue#isnil()

The following examples show how to use org.luaj.vm2.LuaValue#isnil() . 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: BaseLib.java    From luaj with MIT License 5 votes vote down vote up
public LuaValue call(LuaValue e, LuaValue base) {
	if (base.isnil())
		return e.tonumber();
	final int b = base.checkint();
	if ( b < 2 || b > 36 )
		argerror(2, "base out of range");
	return e.checkstring().tonumber(b);
}
 
Example 2
Source File: CoerceLuaToJava.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
public Object coerce(LuaValue value) {
	if ( value.isnil() )
		return null;
	if ( targetType == TARGET_TYPE_STRING )
		return value.tojstring();
	LuaString s = value.checkstring();
	byte[] b = new byte[s.m_length];
	s.copyInto(0, b, 0, b.length);
	return b;
}
 
Example 3
Source File: PackageLib.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	LuaString name = args.checkstring(1);
	LuaValue val = package_.get(_PRELOAD).get(name);
	return val.isnil()? 
		valueOf("\n\tno field package.preload['"+name+"']"):
		val;
}
 
Example 4
Source File: LuajView.java    From luaj with MIT License 5 votes vote down vote up
public void onWindowFocusChanged(boolean hasWindowFocus) {
	LuaValue f = globals.get("onWindowFocusChanged");
	if (!f.isnil())
		try {
			f.call(CoerceJavaToLua.coerce(hasWindowFocus));
		} catch (Exception e) {
			e.printStackTrace();
		}
}
 
Example 5
Source File: LuajView.java    From luaj with MIT License 5 votes vote down vote up
public boolean onTrackballEvent(MotionEvent event) {
	LuaValue f = globals.get("onTrackballEvent");
	if (!f.isnil())
		try {
			return f.call(CoerceJavaToLua.coerce(event)).toboolean();
		} catch (Exception e) {
			e.printStackTrace();
			return true;
		}
	else
		return super.onTrackballEvent(event);
}
 
Example 6
Source File: LuaConversion.java    From Cubes with MIT License 5 votes vote down vote up
public static Object convertToJava(Class<?> c, LuaValue o) {
  if (o == null || o.isnil()) return null;
  LuaConverter luaConverter = converter(c);
  if (luaConverter == null) {
    if (o instanceof LuaObject) {
      luaConverter = map.get(Object.class);
    } else {
      throw new ConversionError("Cannot convert Lua to Java: " + c.getName());
    }
  }
  return luaConverter.toJava(o, c);
}
 
Example 7
Source File: LuajView.java    From luaj with MIT License 5 votes vote down vote up
public boolean onKeyUp(int keyCode, KeyEvent event) {
	LuaValue f = globals.get("onKeyUp");
	if (!f.isnil())
		try {
			return f.call(CoerceJavaToLua.coerce(keyCode),
					CoerceJavaToLua.coerce(event)).toboolean();
		} catch (Exception e) {
			e.printStackTrace();
			return true;
		}
	else
		return super.onKeyUp(keyCode, event);
}
 
Example 8
Source File: BaseLib.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
public LuaValue call(LuaValue arg) {
	LuaValue h = arg.metatag(TOSTRING);
	if ( ! h.isnil() ) 
		return h.call(arg);
	LuaValue v = arg.tostring();
	if ( ! v.isnil() ) 
		return v;
	return valueOf(arg.tojstring());
}
 
Example 9
Source File: BaseLib.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
public LuaValue call(LuaValue e, LuaValue base) {
	if (base.isnil())
		return e.tonumber();
	final int b = base.checkint();
	if ( b < 2 || b > 36 )
		argerror(2, "base out of range");
	return e.checkstring().tonumber(b);
}
 
Example 10
Source File: UDBaseListView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 调用Header函数
 *
 * @return
 */
public UDView setHeader(LuaValue header) {
     T lv = getView();
    if (lv instanceof ILVListView) {
        if (header instanceof UDView) {
            mHeader = header;
            ((ILVListView) lv).addHeader(((UDView) header).getView());
        } else if (header == null || header.isnil()) {
            mHeader = NIL;
            ((ILVListView) lv).removeHeader();
        }
    }
    return this;
}
 
Example 11
Source File: LuaViewCore.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 注册一个名称到该lua对象的命名空间中
 *
 * @param luaName
 * @param clazz
 * @return
 */
public synchronized LuaViewCore registerPanel(String luaName, Class<? extends LVCustomPanel> clazz) {
    if (mGlobals != null && !TextUtils.isEmpty(luaName) && (clazz != null && clazz.getSuperclass() == LVCustomPanel.class)) {
        LuaValue value = mGlobals.get(luaName);
        if (value == null || value.isnil()) {
            mGlobals.tryLazyLoad(new UICustomPanelBinder(clazz, luaName));
        }
    }
    return this;
}
 
Example 12
Source File: CustomItem.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
private Item applyOnItem(int cell,String effect) {
    LuaValue ret = script.run(effect, cell);
    if(ret.isnil()) {
        return null;
    }

    Item item = (Item) ret.checkuserdata(Item.class);
    item.quantity(quantity());
    return item;
}
 
Example 13
Source File: BaseLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public LuaValue call(LuaValue e, LuaValue base) {
    if (base.isnil())
        return e.tonumber();
     int b = base.checkint();
    if (b < 2 || b > 36)
        argerror(2, "base out of range");
    return e.checkstring().tonumber(b);
}
 
Example 14
Source File: PackageLib.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	LuaString name = args.checkstring(1);
	LuaValue val = package_.get(_PRELOAD).get(name);
	return val.isnil()? 
		valueOf("\n\tno field package.preload['"+name+"']"):
		val;
}
 
Example 15
Source File: BaseLib.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
public LuaValue call(LuaValue arg) {
    LuaValue h = arg.metatag(TOSTRING);
    if (!h.isnil()) {
        return h.call(arg);
    }
    LuaValue v = arg.tostring();
    if (!v.isnil()) {
        return v;
    }
    return valueOf(arg.tojstring());
}
 
Example 16
Source File: IoLib.java    From luaj with MIT License 4 votes vote down vote up
public Varargs _io_input(LuaValue file) {
	infile = file.isnil()? input():
			file.isstring()? ioopenfile(FTYPE_NAMED, file.checkjstring(),"r"):
			checkfile(file);
	return infile;
}
 
Example 17
Source File: BaseLib.java    From XPrivacyLua with GNU General Public License v3.0 4 votes vote down vote up
public LuaValue call(LuaValue arg1, LuaValue arg2) {
	throw arg1.isnil()? new LuaError(null, arg2.optint(1)): 
		arg1.isstring()? new LuaError(arg1.tojstring(), arg2.optint(1)): 
			new LuaError(arg1);
}
 
Example 18
Source File: IoLib.java    From XPrivacyLua with GNU General Public License v3.0 4 votes vote down vote up
public Varargs _io_output(LuaValue filename) {
	outfile = filename.isnil()? output(): 
			  filename.isstring()? ioopenfile(FTYPE_NAMED, filename.checkjstring(),"w"):
			  checkfile(filename);
	return outfile;
}
 
Example 19
Source File: IoLib.java    From HtmlNative with Apache License 2.0 4 votes vote down vote up
public Varargs _io_output(LuaValue filename) {
	outfile = filename.isnil()? output(): 
			  filename.isstring()? ioopenfile(FTYPE_NAMED, filename.checkjstring(),"w"):
			  checkfile(filename);
	return outfile;
}
 
Example 20
Source File: UDBaseListOrRecyclerView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 是否有某个函数
 *
 * @param cellId
 * @param method
 * @return
 */
public boolean hasCellFunction(String cellId, String method) {
     LuaValue methodData = getCell(cellId);
    return !methodData.isnil() && methodData.get(method) != null && methodData.get(method).isfunction();
}