Java Code Examples for org.luaj.vm2.LoadState

The following examples show how to use org.luaj.vm2.LoadState. These examples are extracted from open source projects. 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 Project: VideoOS-Android-SDK   Author: VideoOS   File: JsePlatform.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
     * Create a standard set of globals for JSE including all the libraries.
     *
     * @return Table of globals initialized with the standard JSE libraries
     * @see #debugGlobals()
     * @see JsePlatform
     * @see JmePlatform
     */
    public static Globals standardGlobals(Globals globals) {
        globals.load(new JseBaseLib());
        globals.load(new PackageLib());
        globals.load(new Bit32Lib());
        globals.load(new TableLib());
        globals.load(new StringLib());
        globals.load(new CoroutineLib());
        globals.load(new JseMathLib());
        globals.load(new JseOsLib());
//		globals.load(new JseIoLib());//安全考虑,删除for LuaView
//		globals.load(new LuajavaLib());//安全考虑,删除for LuaView
        LoadState.install(globals);
        LuaC.install(globals);
        return globals;
    }
 
Example #2
Source Project: XPrivacyLua   Author: M66B   File: JsePlatform.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create a standard set of globals for JSE including all the libraries.
 * 
 * @return Table of globals initialized with the standard JSE libraries
 * @see #debugGlobals()
 * @see org.luaj.vm2.lib.jse.JsePlatform
 * @see org.luaj.vm2.lib.jme.JmePlatform
 */
public static Globals standardGlobals() {
	Globals globals = new Globals();
	globals.load(new JseBaseLib());
	globals.load(new PackageLib());
	globals.load(new Bit32Lib());
	globals.load(new TableLib());
	globals.load(new StringLib());
	globals.load(new CoroutineLib());
	globals.load(new JseMathLib());
	globals.load(new JseIoLib());
	globals.load(new JseOsLib());
	globals.load(new LuajavaLib());
	LoadState.install(globals);
	LuaC.install(globals);
	return globals;		
}
 
Example #3
Source Project: luaj   Author: luaj   File: JsePlatform.java    License: MIT License 6 votes vote down vote up
/**
 * Create a standard set of globals for JSE including all the libraries.
 * 
 * @return Table of globals initialized with the standard JSE libraries
 * @see #debugGlobals()
 * @see org.luaj.vm2.lib.jse.JsePlatform
 * @see org.luaj.vm2.lib.jme.JmePlatform
 */
public static Globals standardGlobals() {
	Globals globals = new Globals();
	globals.load(new JseBaseLib());
	globals.load(new PackageLib());
	globals.load(new Bit32Lib());
	globals.load(new TableLib());
	globals.load(new JseStringLib());
	globals.load(new CoroutineLib());
	globals.load(new JseMathLib());
	globals.load(new JseIoLib());
	globals.load(new JseOsLib());
	globals.load(new LuajavaLib());
	LoadState.install(globals);
	LuaC.install(globals);
	return globals;
}
 
Example #4
Source Project: luaj   Author: luaj   File: JmePlatform.java    License: MIT License 6 votes vote down vote up
/**
 * Create a standard set of globals for JME including all the libraries.
 * 
 * @return Table of globals initialized with the standard JME libraries
 * @see #debugGlobals()
 * @see org.luaj.vm2.lib.jse.JsePlatform
 * @see org.luaj.vm2.lib.jme.JmePlatform
 */
public static Globals standardGlobals() {
	Globals globals = new Globals();
	globals.load(new BaseLib());
	globals.load(new PackageLib());
	globals.load(new Bit32Lib());
	globals.load(new OsLib());
	globals.load(new MathLib());
	globals.load(new TableLib());
	globals.load(new StringLib());
	globals.load(new CoroutineLib());
	globals.load(new JmeIoLib());
	LoadState.install(globals);
	LuaC.install(globals);
	return globals;		
}
 
Example #5
Source Project: remixed-dungeon   Author: NYRDS   File: LuaEngine.java    License: GNU General Public License v3.0 6 votes vote down vote up
private LuaEngine() {
	globals = new Globals();
	globals.load(new JseBaseLib());
	globals.load(new PackageLib());
	globals.load(new Bit32Lib());
	globals.load(new TableLib());
	globals.load(new StringLib());
	globals.load(new CoroutineLib());
	globals.load(new JseMathLib());
	globals.load(new JseIoLib());
	globals.load(new JseOsLib());
	globals.load(new MultiDexLuajavaLib());
	LoadState.install(globals);
	LuaC.install(globals);

	globals.finder = this;
	globals.set("loadResource", new resLoader());
}
 
Example #6
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: DumpState.java    License: GNU General Public License v3.0 5 votes vote down vote up
void dumpHeader() throws IOException {
	writer.write( LoadState.LUA_SIGNATURE );
	writer.write( LoadState.LUAC_VERSION );
	writer.write( LoadState.LUAC_FORMAT );
	writer.write( IS_LITTLE_ENDIAN? 1: 0 );
	writer.write( SIZEOF_INT );
	writer.write( SIZEOF_SIZET );
	writer.write( SIZEOF_INSTRUCTION );
	writer.write( SIZEOF_LUA_NUMBER );
	writer.write( NUMBER_FORMAT );
	writer.write( LoadState.LUAC_TAIL );
}
 
Example #7
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: ScriptBundleLoadDelegate.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * load a prototype
 *
 * @param scriptFile
 * @return
 */
private Prototype loadPrototype( ScriptFile scriptFile) {
    if (LoadState.instance != null && scriptFile != null) {
        try {
            return LoadState.instance.undump(new BufferedInputStream(new ByteArrayInputStream(scriptFile.scriptData)), scriptFile.getFilePath());//TODO 低端机性能上可以进一步优化
        } catch (LuaError error) {
        } catch (Exception e) {
        }
    }
    return null;
}
 
Example #8
Source Project: XPrivacyLua   Author: M66B   File: DumpState.java    License: GNU General Public License v3.0 5 votes vote down vote up
void dumpHeader() throws IOException {
	writer.write( LoadState.LUA_SIGNATURE );
	writer.write( LoadState.LUAC_VERSION );
	writer.write( LoadState.LUAC_FORMAT );
	writer.write( IS_LITTLE_ENDIAN? 1: 0 );
	writer.write( SIZEOF_INT );
	writer.write( SIZEOF_SIZET );
	writer.write( SIZEOF_INSTRUCTION );
	writer.write( SIZEOF_LUA_NUMBER );
	writer.write( NUMBER_FORMAT );
	writer.write( LoadState.LUAC_TAIL );
}
 
Example #9
Source Project: HtmlNative   Author: hsllany   File: JsePlatform.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a standard set of globals for JSE including all the libraries.
 *
 * @return Table of globals initialized with the standard JSE libraries
 * @see #debugGlobals()
 * @see org.luaj.vm2.lib.jse.JsePlatform
 * @see org.luaj.vm2.lib.jme.JmePlatform
 */
public static Globals standardGlobals() {
    Globals globals = new Globals();
    globals.load(new JseBaseLib());
    globals.load(new PackageLib());
    globals.load(new Bit32Lib());
    globals.load(new TableLib());
    globals.load(new StringLib());
    globals.load(new JseMathLib());
    globals.load(new JseOsLib());
    LoadState.install(globals);
    LuaC.install(globals);
    return globals;
}
 
Example #10
Source Project: HtmlNative   Author: hsllany   File: DumpState.java    License: Apache License 2.0 5 votes vote down vote up
void dumpHeader() throws IOException {
	writer.write( LoadState.LUA_SIGNATURE );
	writer.write( LoadState.LUAC_VERSION );
	writer.write( LoadState.LUAC_FORMAT );
	writer.write( IS_LITTLE_ENDIAN? 1: 0 );
	writer.write( SIZEOF_INT );
	writer.write( SIZEOF_SIZET );
	writer.write( SIZEOF_INSTRUCTION );
	writer.write( SIZEOF_LUA_NUMBER );
	writer.write( NUMBER_FORMAT );
	writer.write( LoadState.LUAC_TAIL );
}
 
Example #11
Source Project: luaj   Author: luaj   File: SampleApplet.java    License: MIT License 5 votes vote down vote up
public void init() {
	// Find the script to load from the applet parameters.
	String script = getParameter(script_parameter);
	if (script == null)
		script = default_script;
	System.out.println("Loading " + script);

	// Construct globals specific to the applet platform.
	globals = new Globals();
	globals.load(new JseBaseLib());
	globals.load(new PackageLib());
	globals.load(new Bit32Lib());
	globals.load(new TableLib());
	globals.load(new JseStringLib());
	globals.load(new CoroutineLib());
	globals.load(new JseMathLib());
	globals.load(new JseIoLib());
	globals.load(new JseOsLib());
	globals.load(new AppletLuajavaLib());
	LoadState.install(globals);
	LuaC.install(globals);

	// Use custom resource finder.
	globals.finder = this;

	// Look up and save the handy pcall method.
	pcall = globals.get("pcall");

	// Load and execute the script, supplying this Applet as the only
	// argument.
	globals.loadfile(script).call(CoerceJavaToLua.coerce(this));
}
 
Example #12
Source Project: luaj   Author: luaj   File: DumpState.java    License: MIT License 5 votes vote down vote up
void dumpHeader() throws IOException {
	writer.write( LoadState.LUA_SIGNATURE );
	writer.write( LoadState.LUAC_VERSION );
	writer.write( LoadState.LUAC_FORMAT );
	writer.write( IS_LITTLE_ENDIAN? 1: 0 );
	writer.write( SIZEOF_INT );
	writer.write( SIZEOF_SIZET );
	writer.write( SIZEOF_INSTRUCTION );
	writer.write( SIZEOF_LUA_NUMBER );
	writer.write( NUMBER_FORMAT );
	writer.write( LoadState.LUAC_TAIL );
}
 
Example #13
Source Project: luaj   Author: luaj   File: SampleSandboxed.java    License: MIT License 4 votes vote down vote up
public static void main(String[] args) {
	// Create server globals with just enough library support to compile user scripts.
	server_globals = new Globals();
	server_globals.load(new JseBaseLib());
	server_globals.load(new PackageLib());
	server_globals.load(new JseStringLib());

	// To load scripts, we occasionally need a math library in addition to compiler support.
	// To limit scripts using the debug library, they must be closures, so we only install LuaC.
	server_globals.load(new JseMathLib());
	LoadState.install(server_globals);
	LuaC.install(server_globals);

	// Set up the LuaString metatable to be read-only since it is shared across all scripts.
	LuaString.s_metatable = new ReadOnlyLuaTable(LuaString.s_metatable);

	// Example normal scripts that behave as expected.
	runScriptInSandbox( "return 'foo'" );
	runScriptInSandbox( "return ('abc'):len()" );
	runScriptInSandbox( "return getmetatable('abc')" );
	runScriptInSandbox( "return getmetatable('abc').len" );
	runScriptInSandbox( "return getmetatable('abc').__index" );

	// Example user scripts that attempt rogue operations, and will fail.
	runScriptInSandbox( "return setmetatable('abc', {})" );
	runScriptInSandbox( "getmetatable('abc').len = function() end" );
	runScriptInSandbox( "getmetatable('abc').__index = {}" );
	runScriptInSandbox( "getmetatable('abc').__index.x = 1" );
	runScriptInSandbox( "while true do print('loop') end" );
	
	// Example use of other shared metatables, which should also be made read-only.
	// This toy example allows booleans to be added to numbers.
	runScriptInSandbox( "return 5 + 6, 5 + true, false + 6" );
	LuaBoolean.s_metatable = new ReadOnlyLuaTable(LuaValue.tableOf(new LuaValue[] {
			LuaValue.ADD, new TwoArgFunction() {
				public LuaValue call(LuaValue x, LuaValue y) {
					return LuaValue.valueOf(
							(x == TRUE ? 1.0 : x.todouble()) +
							(y == TRUE ? 1.0 : y.todouble()) );
				}
			},
	}));
	runScriptInSandbox( "return 5 + 6, 5 + true, false + 6" );
}