Java Code Examples for org.luaj.vm2.Globals

The following examples show how to use org.luaj.vm2.Globals. 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: 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 #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: VideoOS-Android-SDK   Author: VideoOS   File: VenvyLVWebView.java    License: GNU General Public License v3.0 6 votes vote down vote up
private Map getViewPriority(Globals globals) {
    try {
        ViewParent view = globals.container.getParent();
        if (view != null) {
            Field field = view.getClass().getDeclaredField("data");
            if (field != null && field.getAnnotation(VenvyAutoData.class) != null) {
                field.setAccessible(true);
                Object targetPriority = field.get(view);
                if (targetPriority != null && targetPriority instanceof Map) {
                    return (Map) targetPriority;
                }
            }
        }
    } catch (Exception e) {
        //忽略此处异常
    }
    return new HashMap();
}
 
Example #4
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: VenvyLVWebView.java    License: GNU General Public License v3.0 6 votes vote down vote up
/***
 * JS交互参数 获取开发者id
 * @param globals
 * @return
 */
private String getDeveloperUserId(Globals globals) {
    String developerUserId = null;
    Map<String, String> dataParams = getViewPriority(globals);
    if (dataParams.size() <= 0) {
        return developerUserId;
    }
    try {
        JSONObject dataObj = new JSONObject(dataParams.get("data"));
        JSONObject miniAppInfoObj = dataObj.optJSONObject("miniAppInfo");
        developerUserId = miniAppInfoObj != null ? miniAppInfoObj.optString("developerUserId") : "";
    } catch (Exception e) {
        e.printStackTrace();
    }
    return developerUserId;
}
 
Example #5
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: UDAlign.java    License: GNU General Public License v3.0 6 votes vote down vote up
public UDAlign(Globals globals, LuaValue metatable) {
    super(globals, metatable);
    set("LEFT", RelativeLayout.ALIGN_PARENT_LEFT);
    set("TOP", RelativeLayout.ALIGN_PARENT_TOP);
    set("RIGHT", RelativeLayout.ALIGN_PARENT_RIGHT);
    set("BOTTOM", RelativeLayout.ALIGN_PARENT_BOTTOM);
    set("CENTER", RelativeLayout.CENTER_IN_PARENT);
    set("H_CENTER", RelativeLayout.CENTER_HORIZONTAL);
    set("V_CENTER", RelativeLayout.CENTER_VERTICAL);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        set("START", RelativeLayout.ALIGN_PARENT_START);
        set("END", RelativeLayout.ALIGN_PARENT_END);
    } else {
        set("START", RelativeLayout.ALIGN_PARENT_LEFT);
        set("END", RelativeLayout.ALIGN_PARENT_RIGHT);
    }
}
 
Example #6
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 #7
Source Project: Bytecoder   Author: mirkosertic   File: LuaTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testLuaReturnString() {
    final Globals theGlobals = new Globals();
    LuaC.install(theGlobals);
    final LuaValue chunk = theGlobals.load("return 'hello, world'");
    final LuaString theResult = chunk.call().strvalue();
    Assert.assertEquals("hello, world", theResult.tojstring());
}
 
Example #8
Source Project: luaj   Author: luaj   File: TestLuaJ.java    License: MIT License 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	System.out.println(script);
	
	// create an environment to run in
	Globals globals = JsePlatform.standardGlobals();
	
	// compile into a chunk, or load as a class
	LuaValue chunk = globals.load(script, "script");
	
	// The loaded chunk should be a closure, which contains the prototype.
	print( chunk.checkclosure().p );

	// The chunk can be called with arguments as desired.
	chunk.call(LuaValue.ZERO, LuaValue.ONE);
}
 
Example #9
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: LVRefreshRecyclerView.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void init(Globals globals) {
    globals.saveContainer(mRecyclerView);
    this.addView(mRecyclerView, LuaViewUtil.createRelativeLayoutParamsMM());
    globals.restoreContainer();

    if (!globals.isRefreshContainerEnable) {
        this.setEnabled(false);
    } else {
        ((UDRefreshRecyclerView) getUserdata()).initPullRefresh();
    }
}
 
Example #10
Source Project: luaj   Author: luaj   File: JsePlatformTest.java    License: MIT License 5 votes vote down vote up
public void testLuaMainPassesArguments() {
	Globals globals = JsePlatform.standardGlobals();   
	LuaValue chunk = globals.load("return #arg, arg.n, arg[2], arg[1]");
	Varargs results = JsePlatform.luaMain(chunk, new String[] { "aaa", "bbb" });
	assertEquals(results.narg(), 4);
	assertEquals(results.arg(1), LuaValue.valueOf(2));
	assertEquals(results.arg(2), LuaValue.valueOf(2));
	assertEquals(results.arg(3), LuaValue.valueOf("bbb"));
	assertEquals(results.arg(4), LuaValue.valueOf("aaa"));
}
 
Example #11
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: LVCustomViewPagerIndicator.java    License: GNU General Public License v3.0 5 votes vote down vote up
public LVCustomViewPagerIndicator(Globals globals, LuaValue metaTable, Varargs varargs) {
    super(globals.getContext());
    this.mInitParams = varargs != null ? varargs.arg1() : null;
    this.mLuaUserdata = new UDCustomViewPagerIndicator(this, globals, metaTable, this.mInitParams);
    this.mLayout = new IcsLinearLayout(globals.getContext(), R.attr.lv_vpiIconPageIndicatorStyle);
    this.setHorizontalScrollBarEnabled(false);
    super.addView(mLayout, LuaViewUtil.createRelativeLayoutParamsMM());
}
 
Example #12
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: LVRecyclerView.java    License: GNU General Public License v3.0 5 votes vote down vote up
void init(Globals globals) {
    mAdapter = new LVRecyclerViewAdapter(globals, mLuaUserdata);
    this.setAdapter(mAdapter);
    mLayoutManager = new LVGridLayoutManager(this);
    this.setLayoutManager(mLayoutManager);
    mLuaUserdata.initOnScrollCallback(this);
    this.setHasFixedSize(true);
    initViewHolderPool();
}
 
Example #13
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: LVHorizontalScrollView.java    License: GNU General Public License v3.0 5 votes vote down vote up
void init(Globals globals) {
    this.setHorizontalScrollBarEnabled(false);//不显示滚动条
    this.setOverScrollMode(OVER_SCROLL_NEVER);
    mContainer = new LinearLayout(globals.getContext());
    mContainer.setOrientation(LinearLayout.HORIZONTAL);
    super.addView(mContainer, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
}
 
Example #14
Source Project: HtmlNative   Author: hsllany   File: LuaRunnerTest.java    License: Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #15
Source Project: luaj   Author: luaj   File: App.java    License: MIT License 5 votes vote down vote up
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.load(script, "maven-exmaple");

// Use any of the "call()" or "invoke()" functions directly on the chunk.
chunk.call();
  }
 
Example #16
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: LuaViewManager.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 创建Globals
 * 根据是否用lua-to-java bytecode来处理(如果使用LuaJC的话则会使用库bcel 533k)
 *
 * @return
 */
public static Globals createGlobals() {
    if (sStaticGlobals != null) {
        synchronized (sStaticGlobals) {
            Globals result = sStaticGlobals;
            sStaticGlobals = null;
            return result;
        }
    } else {
        return setupGlobals(new Globals());
    }
}
 
Example #17
Source Project: Bytecoder   Author: mirkosertic   File: LuaTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testLuaReturnInteger() {
    final Globals theGlobals = new Globals();
    LuaC.install(theGlobals);
    final LuaValue chunk = theGlobals.load("return 123");
    final LuaString theResult = chunk.call().strvalue();
    Assert.assertEquals("123", theResult.tojstring());
}
 
Example #18
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: UDAnimator.java    License: GNU General Public License v3.0 5 votes vote down vote up
public UDAnimator(Globals globals, LuaValue metaTable, Varargs varargs) {
    super(new ObjectAnimator(), globals, metaTable, varargs);
    ObjectAnimator animator = getAnimator();
    if (animator != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            animator.setAutoCancel(true);
        }
    }
}
 
Example #19
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: BaseCacheUserdata.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void cacheObject() {
    Globals globals = getGlobals();
    LuaCache luaCache = globals != null ? globals.getLuaCache() : null;
    if (luaCache != null) {
        luaCache.cacheObject(getClass(), this);
    }
}
 
Example #20
Source Project: Bytecoder   Author: mirkosertic   File: LuaTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testLuaReturnIntegerAdd() {
    final Globals theGlobals = new Globals();
    LuaC.install(theGlobals);
    final LuaValue chunk = theGlobals.load("return 123 + 231");
    final LuaString theResult = chunk.call().strvalue();
    Assert.assertEquals("354", theResult.tojstring());
}
 
Example #21
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: UDSystem.java    License: GNU General Public License v3.0 5 votes vote down vote up
public UDSystem(Globals globals, LuaValue metatable) {
    super(globals, metatable);
    set("ios", new ios());//是否ios
    set("android", new android());//是否android
    set("sdkVersion", new sdkVersion());//LuaView版本
    set("osVersion", new osVersion());//系统版本
    set("platform", new platform());//平台信息
    set("scale", new scale());//屏幕分辨率
    set("device", new device());//设备信息
    set("screenSize", new screenSize());//屏幕尺寸
    set("gc", new gc());
    set("keepScreenOn", new keepScreenOn());
}
 
Example #22
Source Project: luaj   Author: luaj   File: AppTest.java    License: MIT License 5 votes vote down vote up
public void testDirectEvaluation() {
  	String script = "return math.pow(..., 3)";
Globals globals = JsePlatform.standardGlobals();
LuaValue chunk = globals.load(script, "cube");
      int result = chunk.call(LuaValue.valueOf(5)).toint();
      assertEquals(125, result);
  }
 
Example #23
Source Project: HtmlNative   Author: hsllany   File: JsePlatform.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Simple wrapper for invoking a lua function with command line arguments.
 * The supplied function is first given a new Globals object,
 * then the program is run with arguments.
 */
public static void luaMain(LuaValue mainChunk, String[] args) {
    Globals g = standardGlobals();
    int n = args.length;
    LuaValue[] vargs = new LuaValue[args.length];
    for (int i = 0; i < n; ++i)
        vargs[i] = LuaValue.valueOf(args[i]);
    LuaValue arg = LuaValue.listOf(vargs);
    arg.set("n", n);
    g.set("arg", arg);
    mainChunk.initupvalue1(g);
    mainChunk.invoke(LuaValue.varargsOf(vargs));
}
 
Example #24
Source Project: Bytecoder   Author: mirkosertic   File: LuaTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testLuaConversion() {
    final Globals theGlobals = new Globals();
    LuaC.install(theGlobals);
    theGlobals.set("key", 10);
    Assert.assertEquals(10, theGlobals.get("key").toint());
    Assert.assertEquals(10, theGlobals.get(LuaString.valueOf("key")).toint());

    final LuaValue chunk = theGlobals.load("return key").call();
    Assert.assertEquals(10, chunk.toint());
}
 
Example #25
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: UDTextView.java    License: GNU General Public License v3.0 4 votes vote down vote up
public UDTextView(T view, Globals globals, LuaValue metatable, Varargs initParams) {
    super(view, globals, metatable, initParams);
}
 
Example #26
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: VenvyUDMediaLifeCycle.java    License: GNU General Public License v3.0 4 votes vote down vote up
public VenvyUDMediaLifeCycle(Platform platform, VenvyLVMediaCallback view, Globals globals, LuaValue metatable, Varargs initParams) {
    super(view, globals, metatable, initParams);
    this.platform = platform;
}
 
Example #27
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: LVListView.java    License: GNU General Public License v3.0 4 votes vote down vote up
private void init(Globals globals) {
    globals.saveContainer(this);
    initData(globals);
    globals.restoreContainer();
}
 
Example #28
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: LVViewGroup.java    License: GNU General Public License v3.0 4 votes vote down vote up
public LVViewGroup(Context context, Globals globals, LuaValue metaTable, Varargs varargs) {
    super(context);
    this.mLuaUserdata = createUserdata(globals, metaTable, varargs);
}
 
Example #29
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: LVRefreshListView.java    License: GNU General Public License v3.0 4 votes vote down vote up
public LVRefreshListView(Globals globals, LuaValue metaTable, Varargs varargs) {
    super(globals.getContext());
    this.mListView = new LVListView(globals, metaTable, varargs, new UDRefreshListView(this, globals, metaTable, varargs));
    init(globals);
}
 
Example #30
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: UDInterpolator.java    License: GNU General Public License v3.0 4 votes vote down vote up
public UDInterpolator(Globals globals, LuaValue metatable) {
    super(globals, metatable);
    init();
}