global var / load as java class #36

Closed
opened 2019-03-17 08:12:02 +00:00 by zaoqi · 4 comments
zaoqi commented 2019-03-17 08:12:02 +00:00 (Migrated from github.com)
...
local __TS__ArrayPush = function(arr, ...)
    local items = ({...});
    for ____TS_index = 1, #items do
        local item = items[____TS_index];
        arr[(#arr) + 1] = item;
    end
    return #arr;
end;
...

testtemp.java

import org.luaj.vm2.*;
import org.luaj.vm2.lib.jse.*;
import java.util.Vector;

public class testtemp {

  private static Globals globals;
  private static boolean print = false;
  private static String encoding = null;

  public static void main(String[] args) throws Exception {

    // process args
    boolean interactive = (args.length == 0);
    boolean versioninfo = false;
    boolean processing = true;
    boolean nodebug = false;
    boolean luajc = false;
    Vector libs = null;

    // new lua state
    globals = JsePlatform.standardGlobals();
    String libname = "lang$luaj";
    LuaValue slibname = LuaValue.valueOf(libname);
    // load as java class
    LuaValue v = (LuaValue)Class.forName(libname).newInstance();
    v.call(slibname, globals);
    System.out.println("load as java class");
  }
}

If I remove local

Exception in thread "main" java.lang.NullPointerException
        at lang$luaj.onInvoke(lang$luaj.lua:28)
        at org.luaj.vm2.lib.VarArgFunction.invoke(Unknown Source)
        at org.luaj.vm2.lib.VarArgFunction.call(Unknown Source)
        at testtemp.main(testtemp.java:27)
```lua ... local __TS__ArrayPush = function(arr, ...) local items = ({...}); for ____TS_index = 1, #items do local item = items[____TS_index]; arr[(#arr) + 1] = item; end return #arr; end; ... ``` testtemp.java ```java import org.luaj.vm2.*; import org.luaj.vm2.lib.jse.*; import java.util.Vector; public class testtemp { private static Globals globals; private static boolean print = false; private static String encoding = null; public static void main(String[] args) throws Exception { // process args boolean interactive = (args.length == 0); boolean versioninfo = false; boolean processing = true; boolean nodebug = false; boolean luajc = false; Vector libs = null; // new lua state globals = JsePlatform.standardGlobals(); String libname = "lang$luaj"; LuaValue slibname = LuaValue.valueOf(libname); // load as java class LuaValue v = (LuaValue)Class.forName(libname).newInstance(); v.call(slibname, globals); System.out.println("load as java class"); } } ``` ------------------------ If I remove `local ` ``` Exception in thread "main" java.lang.NullPointerException at lang$luaj.onInvoke(lang$luaj.lua:28) at org.luaj.vm2.lib.VarArgFunction.invoke(Unknown Source) at org.luaj.vm2.lib.VarArgFunction.call(Unknown Source) at testtemp.main(testtemp.java:27) ```
Enyby commented 2019-03-17 13:05:43 +00:00 (Migrated from github.com)

Understood nothing. You should at least quote the code "lang$luaj".

Understood nothing. You should at least quote the code "lang$luaj".
zaoqi commented 2019-03-22 09:13:30 +00:00 (Migrated from github.com)

lang$luaj

...
local __TS__ArrayPush = function(arr, ...)
    local items = ({...});
    for ____TS_index = 1, #items do
        local item = items[____TS_index];
        arr[(#arr) + 1] = item;
    end
    return #arr;
end;
...
`lang$luaj` ```lua ... local __TS__ArrayPush = function(arr, ...) local items = ({...}); for ____TS_index = 1, #items do local item = items[____TS_index]; arr[(#arr) + 1] = item; end return #arr; end; ... ```
noncom commented 2019-03-22 09:41:10 +00:00 (Migrated from github.com)

@zaoqi could you clarify a couple of questions?

  1. which exactly local do you remove so that you are getting this error?
  2. how do you load lang$luaj and what filename does it have? (including the extension)
@zaoqi could you clarify a couple of questions? 1. which exactly `local` do you remove so that you are getting this error? 2. how do you load `lang$luaj` and what filename does it have? (including the extension)
zaoqi commented 2019-03-22 09:51:36 +00:00 (Migrated from github.com)

@noncom

  • local of local __TS__ArrayPush ...
import org.luaj.vm2.*;
import org.luaj.vm2.lib.jse.*;
import java.util.Vector;

public class testtemp {

  private static Globals globals;
  private static boolean print = false;
  private static String encoding = null;

  public static void main(String[] args) throws Exception {

    // process args
    boolean interactive = (args.length == 0);
    boolean versioninfo = false;
    boolean processing = true;
    boolean nodebug = false;
    boolean luajc = false;
    Vector libs = null;

    // new lua state
    globals = JsePlatform.standardGlobals();
    String libname = "lang$luaj";
    LuaValue slibname = LuaValue.valueOf(libname);
    // load as java class
    LuaValue v = (LuaValue)Class.forName(libname).newInstance();
    v.call(slibname, globals);
    System.out.println("load as java class");
  }
}

lang$luaj.class

@noncom * `local` of `local __TS__ArrayPush ...` ```java import org.luaj.vm2.*; import org.luaj.vm2.lib.jse.*; import java.util.Vector; public class testtemp { private static Globals globals; private static boolean print = false; private static String encoding = null; public static void main(String[] args) throws Exception { // process args boolean interactive = (args.length == 0); boolean versioninfo = false; boolean processing = true; boolean nodebug = false; boolean luajc = false; Vector libs = null; // new lua state globals = JsePlatform.standardGlobals(); String libname = "lang$luaj"; LuaValue slibname = LuaValue.valueOf(libname); // load as java class LuaValue v = (LuaValue)Class.forName(libname).newInstance(); v.call(slibname, globals); System.out.println("load as java class"); } } ``` `lang$luaj.class`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: open-autonomous-connection/luaj#36