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

The following examples show how to use org.luaj.vm2.LuaValue#checkglobals() . 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: PackageLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
public LuaValue call(LuaValue modname, LuaValue env) {
    globals = env.checkglobals();
    globals.set("require", new require());
    package_ = new LuaTable();
    package_.set(_LOADED, new LuaTable());
    package_.set(_PRELOAD, new LuaTable());
    package_.set(_PATH, LuaValue.valueOf(DEFAULT_LUA_PATH));
    package_.set(_LOADLIB, new loadlib());
    package_.set(_SEARCHPATH, new searchpath());
    LuaTable searchers = new LuaTable();
    searchers.set(1, preload_searcher = new preload_searcher());
    searchers.set(2, lua_searcher = new lua_searcher());
    searchers.set(3, java_searcher = new java_searcher());
    package_.set(_SEARCHERS, searchers);
    package_.get(_LOADED).set("package", package_);
    env.set("package", package_);
    globals.package_ = this;
    return env;
}
 
Example 2
Source File: IoLib.java    From luaj with MIT License 6 votes vote down vote up
public LuaValue call(LuaValue modname, LuaValue env) {
	globals = env.checkglobals();
	
	// io lib functions
	LuaTable t = new LuaTable();
	bind(t, IoLibV.class, IO_NAMES );
	
	// create file methods table
	filemethods = new LuaTable();
	bind(filemethods, IoLibV.class, FILE_NAMES, FILE_CLOSE );

	// set up file metatable
	LuaTable mt = new LuaTable();
	bind(mt, IoLibV.class, new String[] { "__index" }, IO_INDEX );
	t.setmetatable( mt );
	
	// all functions link to library instance
	setLibInstance( t );
	setLibInstance( filemethods );
	setLibInstance( mt );
	
	// return the table
	env.set("io", t);
	if (!env.get("package").isnil()) env.get("package").get("loaded").set("io", t);
	return t;
}
 
Example 3
Source File: PackageLib.java    From HtmlNative with Apache License 2.0 6 votes vote down vote up
/** Perform one-time initialization on the library by adding package functions
 * to the supplied environment, and returning it as the return value.
 * It also creates the package.preload and package.loaded tables for use by
 * other libraries.
 * @param modname the module name supplied if this is loaded via 'require'.
 * @param env the environment to load into, typically a Globals instance.
 */
public LuaValue call(LuaValue modname, LuaValue env) {
	globals = env.checkglobals();
	globals.set("require", new require());
	package_ = new LuaTable();
	package_.set(_LOADED, new LuaTable());
	package_.set(_PRELOAD, new LuaTable());
	package_.set(_PATH, LuaValue.valueOf(DEFAULT_LUA_PATH));
	package_.set(_LOADLIB, new loadlib());
	package_.set(_SEARCHPATH, new searchpath());
	LuaTable searchers = new LuaTable();
	searchers.set(1, preload_searcher = new preload_searcher());
	searchers.set(2, lua_searcher     = new lua_searcher());
	searchers.set(3, java_searcher    = new java_searcher());
	package_.set(_SEARCHERS, searchers);
	package_.get(_LOADED).set("package", package_);
	env.set("package", package_);
	globals.package_ = this;
	return env;
}
 
Example 4
Source File: DebugLib.java    From XPrivacyLua with GNU General Public License v3.0 6 votes vote down vote up
/** Perform one-time initialization on the library by creating a table
 * containing the library functions, adding that table to the supplied environment,
 * adding the table to package.loaded, and returning table as the return value.
 * @param modname the module name supplied if this is loaded via 'require'.
 * @param env the environment to load into, which must be a Globals instance.
 */
public LuaValue call(LuaValue modname, LuaValue env) {
	globals = env.checkglobals();
	globals.debuglib = this;
	LuaTable debug = new LuaTable();
	debug.set("debug", new debug());
	debug.set("gethook", new gethook());
	debug.set("getinfo", new getinfo());
	debug.set("getlocal", new getlocal());
	debug.set("getmetatable", new getmetatable());
	debug.set("getregistry", new getregistry());
	debug.set("getupvalue", new getupvalue());
	debug.set("getuservalue", new getuservalue());
	debug.set("sethook", new sethook());
	debug.set("setlocal", new setlocal());
	debug.set("setmetatable", new setmetatable());
	debug.set("setupvalue", new setupvalue());
	debug.set("setuservalue", new setuservalue());
	debug.set("traceback", new traceback());
	debug.set("upvalueid", new upvalueid());
	debug.set("upvaluejoin", new upvaluejoin());
	env.set("debug", debug);
	env.get("package").get("loaded").set("debug", debug);
	return debug;
}
 
Example 5
Source File: IoLib.java    From HtmlNative with Apache License 2.0 6 votes vote down vote up
public LuaValue call(LuaValue modname, LuaValue env) {
	globals = env.checkglobals();
	
	// io lib functions
	LuaTable t = new LuaTable();
	bind(t, IoLibV.class, IO_NAMES );
	
	// create file methods table
	filemethods = new LuaTable();
	bind(filemethods, IoLibV.class, FILE_NAMES, FILE_CLOSE );

	// set up file metatable
	LuaTable mt = new LuaTable();
	bind(mt, IoLibV.class, new String[] { "__index" }, IO_INDEX );
	t.setmetatable( mt );
	
	// all functions link to library instance
	setLibInstance( t );
	setLibInstance( filemethods );
	setLibInstance( mt );
	
	// return the table
	env.set("io", t);
	env.get("package").get("loaded").set("io", t);
	return t;
}
 
Example 6
Source File: CoroutineLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public LuaValue call(LuaValue modname, LuaValue env) {
    globals = env.checkglobals();
    LuaTable coroutine = new LuaTable();
    coroutine.set("create", new create());
    coroutine.set("resume", new resume());
    coroutine.set("running", new running());
    coroutine.set("status", new status());
    coroutine.set("yield", new yield());
    coroutine.set("wrap", new wrap());
    env.set("coroutine", coroutine);
    env.get("package").get("loaded").set("coroutine", coroutine);
    return coroutine;
}
 
Example 7
Source File: OsLib.java    From luaj with MIT License 5 votes vote down vote up
/** Perform one-time initialization on the library by creating a table
 * containing the library functions, adding that table to the supplied environment,
 * adding the table to package.loaded, and returning table as the return value.
 * @param modname the module name supplied if this is loaded via 'require'.
 * @param env the environment to load into, typically a Globals instance.
 */
public LuaValue call(LuaValue modname, LuaValue env) {
	globals = env.checkglobals();
	LuaTable os = new LuaTable();
	for (int i = 0; i < NAMES.length; ++i)
		os.set(NAMES[i], new OsLibFunc(i, NAMES[i]));
	env.set("os", os);
	if (!env.get("package").isnil()) env.get("package").get("loaded").set("os", os);
	return os;
}
 
Example 8
Source File: BaseLib.java    From luaj with MIT License 5 votes vote down vote up
/** Perform one-time initialization on the library by adding base functions
 * to the supplied environment, and returning it as the return value.
 * @param modname the module name supplied if this is loaded via 'require'.
 * @param env the environment to load into, which must be a Globals instance.
 */
public LuaValue call(LuaValue modname, LuaValue env) {
	globals = env.checkglobals();
	globals.finder = this;
	globals.baselib = this;
	env.set( "_G", env );
	env.set( "_VERSION", Lua._VERSION );
	env.set("assert", new _assert());
	env.set("collectgarbage", new collectgarbage());
	env.set("dofile", new dofile());
	env.set("error", new error());
	env.set("getmetatable", new getmetatable());
	env.set("load", new load());
	env.set("loadfile", new loadfile());
	env.set("pcall", new pcall());
	env.set("print", new print(this));
	env.set("rawequal", new rawequal());
	env.set("rawget", new rawget());
	env.set("rawlen", new rawlen());
	env.set("rawset", new rawset());
	env.set("select", new select());
	env.set("setmetatable", new setmetatable());
	env.set("tonumber", new tonumber());
	env.set("tostring", new tostring());
	env.set("type", new type());
	env.set("xpcall", new xpcall());

	next next;
	env.set("next", next = new next());
	env.set("pairs", new pairs(next));
	env.set("ipairs", new ipairs());
	
	return env;
}
 
Example 9
Source File: CoroutineLib.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
/** Perform one-time initialization on the library by creating a table
 * containing the library functions, adding that table to the supplied environment,
 * adding the table to package.loaded, and returning table as the return value.
 * @param modname the module name supplied if this is loaded via 'require'.
 * @param env the environment to load into, which must be a Globals instance.
 */
public LuaValue call(LuaValue modname, LuaValue env) {
	globals = env.checkglobals();
	LuaTable coroutine = new LuaTable();
	coroutine.set("create", new create());
	coroutine.set("resume", new resume());
	coroutine.set("running", new running());
	coroutine.set("status", new status());
	coroutine.set("yield", new yield());
	coroutine.set("wrap", new wrap());
	env.set("coroutine", coroutine);
	env.get("package").get("loaded").set("coroutine", coroutine);
	return coroutine;
}
 
Example 10
Source File: CoroutineLib.java    From luaj with MIT License 5 votes vote down vote up
/** Perform one-time initialization on the library by creating a table
 * containing the library functions, adding that table to the supplied environment,
 * adding the table to package.loaded, and returning table as the return value.
 * @param modname the module name supplied if this is loaded via 'require'.
 * @param env the environment to load into, which must be a Globals instance.
 */
public LuaValue call(LuaValue modname, LuaValue env) {
	globals = env.checkglobals();
	LuaTable coroutine = new LuaTable();
	coroutine.set("create", new create());
	coroutine.set("resume", new resume());
	coroutine.set("running", new running());
	coroutine.set("status", new status());
	coroutine.set("yield", new yield());
	coroutine.set("wrap", new wrap());
	env.set("coroutine", coroutine);
	if (!env.get("package").isnil()) env.get("package").get("loaded").set("coroutine", coroutine);
	return coroutine;
}
 
Example 11
Source File: VenvyAppletBinder.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
@Override
public LuaValue createCreator(LuaValue env, LuaValue metaTable) {
    return new UDApplet(env.checkglobals(), metaTable, mPlatform);
}
 
Example 12
Source File: RequireSampleSuccess.java    From luaj with MIT License 4 votes vote down vote up
public LuaValue call(LuaValue modname, LuaValue env) {
	env.checkglobals();
	return LuaValue.valueOf("require-sample-success-"+modname.tojstring());
}
 
Example 13
Source File: VenvyNativeBinder.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
@Override
public LuaValue createCreator(LuaValue env, final LuaValue metaTable) {
    VenvyLVLibBinder venvyLVLibBinder = new VenvyLVLibBinder(env.checkglobals(), metaTable);
    venvyLVLibBinder.installPlugin(this);
    return venvyLVLibBinder;
}
 
Example 14
Source File: TextAlignBinder.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
@Override
public LuaValue createCreator(LuaValue env,  LuaValue metaTable) {
    return new UDTextAlign(env.checkglobals(), metaTable);
}
 
Example 15
Source File: EllipsizeBinder.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
@Override
public LuaValue createCreator(LuaValue env, LuaValue metaTable) {
    return new UDEllipsize(env.checkglobals(), metaTable);
}
 
Example 16
Source File: InterpolatorBinder.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
@Override
public LuaValue createCreator(LuaValue env,  LuaValue metaTable) {
    return new UDInterpolator(env.checkglobals(), metaTable);
}
 
Example 17
Source File: PinnedBinder.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
@Override
public LuaValue createCreator(LuaValue env,  LuaValue metaTable) {
    return new UDPinned(env.checkglobals(), metaTable);
}
 
Example 18
Source File: SystemBinder.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
@Override
public LuaValue createCreator(LuaValue env, LuaValue metaTable) {
    return new UDSystem(env.checkglobals(), metaTable);
}
 
Example 19
Source File: JseBaseLib.java    From HtmlNative with Apache License 2.0 2 votes vote down vote up
/** Perform one-time initialization on the library by creating a table
 * containing the library functions, adding that table to the supplied environment,
 * adding the table to package.loaded, and returning table as the return value.
 * <P>Specifically, extend the library loading to set the default value for {@link Globals#STDIN}
 * @param modname the module name supplied if this is loaded via 'require'.
 * @param env the environment to load into, which must be a Globals instance.
 */
public LuaValue call(LuaValue modname, LuaValue env) {
	super.call(modname, env);
	env.checkglobals().STDIN = System.in;
	return env;
}
 
Example 20
Source File: JseBaseLib.java    From XPrivacyLua with GNU General Public License v3.0 2 votes vote down vote up
/** Perform one-time initialization on the library by creating a table
 * containing the library functions, adding that table to the supplied environment,
 * adding the table to package.loaded, and returning table as the return value.
 * <P>Specifically, extend the library loading to set the default value for {@link Globals#STDIN}
 * @param modname the module name supplied if this is loaded via 'require'.
 * @param env the environment to load into, which must be a Globals instance.
 */
public LuaValue call(LuaValue modname, LuaValue env) {
	super.call(modname, env);
	env.checkglobals().STDIN = System.in;
	return env;
}