本文整理汇总了Java中org.luaj.vm2.lib.jse.JsePlatform.standardGlobals方法的典型用法代码示例。如果您正苦于以下问题:Java JsePlatform.standardGlobals方法的具体用法?Java JsePlatform.standardGlobals怎么用?Java JsePlatform.standardGlobals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.luaj.vm2.lib.jse.JsePlatform
的用法示例。
在下文中一共展示了JsePlatform.standardGlobals方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupGlobals
import org.luaj.vm2.lib.jse.JsePlatform; //导入方法依赖的package包/类
/**
* setup global values
*
* @param globals
*/
private static Globals setupGlobals(Globals globals) {
if (globals != null) {
if (LuaViewConfig.isOpenDebugger()) {
JsePlatform.debugGlobals(globals);
} else {
JsePlatform.standardGlobals(globals);//加载系统libs TODO 性能瓶颈
}
if (LuaViewConfig.isUseLuaDC()) {
LuaDC.install(globals);
}
loadLuaViewLibs(globals);//加载用户lib TODO 性能瓶颈
globals.isInited = true;
}
return globals;
}
示例2: HTTPInputGenerator
import org.luaj.vm2.lib.jse.JsePlatform; //导入方法依赖的package包/类
/**
* Constructs a new HTTPInputGenerator using a Lua generation script.
* The Lua script must contain the onInit() and onCall(callnum) functions.
* onCall(callnum) must return the HTTP request for a specific call with number callnum.
* callnum begins at 1 (Lua convention) and increments for each call. It resets back to 1
* if onCall returns nil.
* @param scriptFile The url generator script.
* @param randomSeed Seed for Lua random function.
* @param timeout The http read timeout.
*/
public HTTPInputGenerator(File scriptFile, int randomSeed, int timeout) {
OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
httpClientBuilder = httpClientBuilder.cookieJar(new JavaNetCookieJar(cookieManager));
if (timeout > 0) {
httpClientBuilder = httpClientBuilder.readTimeout(timeout, TimeUnit.MILLISECONDS)
.connectTimeout(timeout, TimeUnit.MILLISECONDS);
}
httpClient = httpClientBuilder.build();
if (scriptFile != null) {
luaGlobals = JsePlatform.standardGlobals();
//luaGlobals.get("require").call(LuaValue.valueOf("tools.descartes.httploadgenerator.http.lua.HTML"));
LuaValue library = new LuaTable();
library.set("getMatches", new GetMatches(htmlFunctions));
library.set("extractMatches", new ExtractAllMatches(htmlFunctions));
luaGlobals.set("html", library);
luaGlobals.get("math").get("randomseed").call(LuaValue.valueOf(5));
luaGlobals.get("dofile").call(LuaValue.valueOf(scriptFile.getAbsolutePath()));
}
}
示例3: main
import org.luaj.vm2.lib.jse.JsePlatform; //导入方法依赖的package包/类
public static void main(String[] args) {
String script = "/lua/luatest.lua";
//URL url = LuaTest.class.getResource(script).toExternalForm();
// From luatest.lua
// function MyAdd( num1, num2 )
// return num1 + num2
// end
//run the lua script defining your function
LuaValue _G = JsePlatform.standardGlobals();
_G.get("dofile").call( LuaValue.valueOf(script));
//call the function MyAdd with two parameters 5, and 5
LuaValue addition = _G.get("MyAdd");
LuaValue retvals = addition.call(LuaValue.valueOf(5), LuaValue.valueOf(5));
//print out the result from the lua function
System.out.println("The result from executing the script is :\n\n" + retvals.tojstring(1));
}
示例4: compile
import org.luaj.vm2.lib.jse.JsePlatform; //导入方法依赖的package包/类
/**
* Compiles this script in preperation for evaluation
*
* @see LuaScript#exec()
*
* @throws ScriptException if the script has already been compiled
*/
public final void compile() throws ScriptException {
// Create globals
globals = JsePlatform.standardGlobals();
// Load libs
LuaValue require = globals.get("require");
DEFAULT_LIBS.forEach(lib -> require.call("clientapi.lua.lib." + lib));
// Compile script
compiled = globals.load(code);
}
示例5: testLuaRunner
import org.luaj.vm2.lib.jse.JsePlatform; //导入方法依赖的package包/类
@Test
public void testLuaRunner() {
String luaScript = Utils.toString(new File("lua_test/test.lua"));
Globals globals = JsePlatform.standardGlobals();
LuaValue value = globals.load(luaScript);
value.invoke();
}
示例6: execute
import org.luaj.vm2.lib.jse.JsePlatform; //导入方法依赖的package包/类
@Test
public void execute() throws Exception {
Globals globals = JsePlatform.standardGlobals();
// globals.set("LCallback", new LCallback());
LuaValue value = globals.load(helloWorldScript);
value.call();
}
示例7: Environment
import org.luaj.vm2.lib.jse.JsePlatform; //导入方法依赖的package包/类
/**
* Constructor. Prepare LuaJ and start game.
* @param game Game to start
* @param player Player in game
*/
public Environment(Game game, Player player) {
Environment.game = game;
lua = JsePlatform.standardGlobals();
registerPlayer(player);
registerGame();
registerIO();
}
示例8: LuaJScript
import org.luaj.vm2.lib.jse.JsePlatform; //导入方法依赖的package包/类
public LuaJScript (LuaJScriptLoader scriptLoader, String script, String name) {
this.script = script;
this.loader = scriptLoader;
this.name = name;
this.context = JsePlatform.standardGlobals();
this.scriptTable = new LuaTable();
}
示例9: main
import org.luaj.vm2.lib.jse.JsePlatform; //导入方法依赖的package包/类
public static void main( String[] args )
{
String script1 = "print('Hello, Mars!')";
String script2 = "print('Running version', _VERSION)";
// create an environment to run in
Globals globals = JsePlatform.standardGlobals();
// Use the convenience function on the globals to load a chunk.
LuaValue chunk = globals.load(script1, "maven-exmaple");
// Use any of the "call()" or "invoke()" functions directly on the chunk.
chunk.call();
}
示例10: main
import org.luaj.vm2.lib.jse.JsePlatform; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
String script = "examples/lua/hello.lua";
// create an environment to run in
LuaValue _G = JsePlatform.standardGlobals();
_G.get("dofile").call( LuaValue.valueOf(script) );
}
示例11: getGlobals
import org.luaj.vm2.lib.jse.JsePlatform; //导入方法依赖的package包/类
public static Globals getGlobals() {
Globals globals = JsePlatform.standardGlobals();
globals.set("collectgarbage", NIL);
globals.set("dofile", NIL);
globals.set("load", NIL);
globals.set("loadfile", NIL);
globals.set("module", NIL);
globals.set("require", NIL);
globals.set("package", NIL);
globals.set("io", NIL);
globals.set("os", NIL);
globals.set("luajava", NIL);
globals.set("debug", NIL);
globals.set("newproxy", NIL);
globals.set("print", new OneArgFunction() {
@Override
public LuaValue call(LuaValue luaValue) {
System.out.println(luaValue.tojstring());
return NIL;
}
});
globals.set("register_callback", new Functions.RegisterCallback());
return globals;
}
示例12: main
import org.luaj.vm2.lib.jse.JsePlatform; //导入方法依赖的package包/类
public static void main( String[] args )
{
String script = "print('hello, world', _VERSION)";
// create an environment to run in
Globals globals = JsePlatform.standardGlobals();
// Use the convenience function on the globals to load a chunk.
LuaValue chunk = globals.loadString(script, "maven-exmaple");
// Use any of the "call()" or "invoke()" functions directly on the chunk.
chunk.call();
}
示例13: testDirectEvaluation
import org.luaj.vm2.lib.jse.JsePlatform; //导入方法依赖的package包/类
public void testDirectEvaluation() {
String script = "return math.pow(..., 3)";
Globals globals = JsePlatform.standardGlobals();
LuaValue chunk = globals.loadString(script, "cube");
int result = chunk.call(LuaValue.valueOf(5)).toint();
assertEquals(125, result);
}
示例14: run
import org.luaj.vm2.lib.jse.JsePlatform; //导入方法依赖的package包/类
public void run() {
try {
// Each thread must have its own Globals.
Globals g = JsePlatform.standardGlobals();
// Once a Globals is created, it can and should be reused
// within the same thread.
g.loadfile(script1).call();
g.loadfile(script2).call();
} catch ( Exception e ) {
e.printStackTrace();
}
}
示例15: main
import org.luaj.vm2.lib.jse.JsePlatform; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
String script = "examples/lua/hello.lua";
// create an environment to run in
Globals globals = JsePlatform.standardGlobals();
// Use the convenience function on Globals to load a chunk.
LuaValue chunk = globals.loadfile(script);
// Use any of the "call()" or "invoke()" functions directly on the chunk.
chunk.call( LuaValue.valueOf(script) );
}