org.luaj.vm2.Globals Java Examples

The following examples show how to use org.luaj.vm2.Globals. 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: LuaEngine.java    From remixed-dungeon with 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 #2
Source File: JsePlatform.java    From luaj with 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 #3
Source File: JsePlatform.java    From XPrivacyLua with 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 #4
Source File: UDAlign.java    From VideoOS-Android-SDK with 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 #5
Source File: VenvyLVWebView.java    From VideoOS-Android-SDK with 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 #6
Source File: VenvyLVWebView.java    From VideoOS-Android-SDK with 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 #7
Source File: LuaViewManager.java    From VideoOS-Android-SDK with 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 #8
Source File: LVCustomViewPagerIndicator.java    From VideoOS-Android-SDK with 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 #9
Source File: TestLuaJ.java    From luaj with 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 #10
Source File: LuaTest.java    From Bytecoder with 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 #11
Source File: JsePlatformTest.java    From luaj with 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 #12
Source File: JsePlatform.java    From HtmlNative with 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 #13
Source File: LVRefreshRecyclerView.java    From VideoOS-Android-SDK with 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 #14
Source File: UDSystem.java    From VideoOS-Android-SDK with 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 #15
Source File: LVRecyclerView.java    From VideoOS-Android-SDK with 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 #16
Source File: LuaTest.java    From Bytecoder with 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 #17
Source File: BaseCacheUserdata.java    From VideoOS-Android-SDK with 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 #18
Source File: UDAnimator.java    From VideoOS-Android-SDK with 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 File: LVHorizontalScrollView.java    From VideoOS-Android-SDK with 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 #20
Source File: LuaRunnerTest.java    From HtmlNative with 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 #21
Source File: LuaTest.java    From Bytecoder with 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 #22
Source File: App.java    From luaj with 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 #23
Source File: LuaTest.java    From Bytecoder with 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 #24
Source File: AppTest.java    From luaj with 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 #25
Source File: BaseVarArgUICreator.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public BaseVarArgUICreator(Globals globals, LuaValue metatable) {
    this(globals, metatable, null);
}
 
Example #26
Source File: UDScrollView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public UDScrollView(LVScrollView view, Globals globals, LuaValue metaTable, LuaValue initParams) {
    super(view, globals, metaTable, initParams);
}
 
Example #27
Source File: UDOrientation.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public UDOrientation(Globals globals, LuaValue metatable) {
    super(globals, metatable);
    init();
}
 
Example #28
Source File: UDImageView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public UDImageView(T view, Globals globals, LuaValue metatable, Varargs initParams) {
    super(view, globals, metatable, initParams);
}
 
Example #29
Source File: LuaViewManager.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
/**
 * tryLazyLoad Android API lib
 * TODO 能否做到按需加载,而不是首次进来加载全部binder
 *
 * @param globals
 */
static void loadLuaViewLibs(final Globals globals) {
    //ui
    globals.tryLazyLoad(new UITextViewBinder());
    globals.tryLazyLoad(new UIEditTextBinder());
    globals.tryLazyLoad(new UIButtonBinder());
    globals.tryLazyLoad(new UIImageViewBinder());
    globals.tryLazyLoad(new UIViewGroupBinder());
    globals.tryLazyLoad(new UIListViewBinder());
    globals.tryLazyLoad(new UIRecyclerViewBinder());
    globals.tryLazyLoad(new UIRefreshListViewBinder());
    globals.tryLazyLoad(new UIRefreshRecyclerViewBinder());
    globals.tryLazyLoad(new UIViewPagerBinder());
    globals.tryLazyLoad(new UICircleViewPagerIndicatorBinder());
    globals.tryLazyLoad(new UIHorizontalScrollViewBinder());
    globals.tryLazyLoad(new UIScrollViewBinder());
    globals.tryLazyLoad(new UILoadingViewBinder());
    globals.tryLazyLoad(new UIToastBinder());
    globals.tryLazyLoad(new SpannableStringBinder());

    globals.tryLazyLoad(new UIRefreshLayoutBinder());

    //animation
    globals.tryLazyLoad(new UIAnimatorBinder());

    //kit
    globals.tryLazyLoad(new TimerBinder());
    globals.tryLazyLoad(new SystemBinder());
    globals.tryLazyLoad(new ActionBarBinder());
    globals.tryLazyLoad(new DataBinder());
    globals.tryLazyLoad(new JsonBinder());
    globals.tryLazyLoad(new FileBinder());

    //常量
    globals.tryLazyLoad(new AlignBinder());
    globals.tryLazyLoad(new TextAlignBinder());
    globals.tryLazyLoad(new FontWeightBinder());
    globals.tryLazyLoad(new FontStyleBinder());
    globals.tryLazyLoad(new ScaleTypeBinder());
    globals.tryLazyLoad(new GravityBinder());
    globals.tryLazyLoad(new OrientationBinder());
    globals.tryLazyLoad(new EllipsizeBinder());
    globals.tryLazyLoad(new InterpolatorBinder());
    globals.tryLazyLoad(new PinnedBinder());
    globals.tryLazyLoad(new ViewEffectBinder());//view特效
    globals.tryLazyLoad(new TouchEventBinder());
}
 
Example #30
Source File: UDRecyclerView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public UDRecyclerView(T view, Globals globals, LuaValue metaTable, Varargs initParams) {
    super(view, globals, metaTable, initParams);
}