OpenComputers icon indicating copy to clipboard operation
OpenComputers copied to clipboard

Lua 5.3 Debug Card NBT-Editing Error

Open J0SLAN opened this issue 8 years ago • 17 comments

Trying to set NBT when the CPU architecture is 5.3 errors out with Error converting entry '<thing>': invalid key to 'next' <thing> is always a list (type 9), so it affects chests with item lists. image

J0SLAN avatar Jul 02 '17 17:07 J0SLAN


~~~The "fix" for now is to simply strip all keys named `n` in lists, although the `setTileNBT` should, of course, ignore this key when iterating.~~~

**Edit**: apparently I was testing on Lua 5.2. This issue only happens on Lua 5.3. Removing `n` doesn't help either.

Fingercomp avatar Jul 05 '17 12:07 Fingercomp

I already tried that. It didn't work. Did you even try it?

J0SLAN avatar Jul 06 '17 06:07 J0SLAN

Oh, sorry. I thought I was testing that on Lua 5.3. It was Lua 5.2.

setNBT doesn't work on Lua 5.3 for me too. :confused:

Fingercomp avatar Jul 06 '17 18:07 Fingercomp

this is failing for the same reason this lua code would fail in 5.3 next({true}, 1.0)

payonel avatar Oct 12 '18 06:10 payonel

this is a bug in our JNLua, its convertLuaValue method in DefaultConverter.java is assuming a lua number is a double. It seems our JNLua code has some 5.2 behavior. In fact, if we update/fix this convert code, we would probably no longer see doubles in all the lua api results (there should be more integers) I don't know what source @fnuecke compiles our jnlua from, but this code i see in the deobf'd source

            case NUMBER:
                luaValueConverter = (DefaultConverter.LuaValueConverter)LUA_VALUE_CONVERTERS.get(formalType);
                if (luaValueConverter != null) {
                    return luaValueConverter.convert(luaState, index);
                }

                if (formalType == Object.class) {
                    return luaState.toNumber(index);
                }
                break;

should do a lua_isinteger check before returning the number. like this:

            case NUMBER:
                luaValueConverter = (DefaultConverter.LuaValueConverter)LUA_VALUE_CONVERTERS.get(formalType);
                if (luaValueConverter != null) {
                    return luaValueConverter.convert(luaState, index);
                }

                if (formalType == Object.class) {
                    if (lua_isinteger(luaState, index))
                        return luaState.toInteger(index)
                    else
                        return luaState.toNumber(index);
                }
                break;

payonel avatar Oct 12 '18 06:10 payonel

removing milestone 1.7.3 because I don't know when sangar will be available to build in jnlua binaries

payonel avatar Oct 12 '18 06:10 payonel

With 5.3 being default architecture this bug became more important. Essentially all integer values reported to LUA are represented as doubles. How come JNLua is compiled from unknown sources?

repo-alt avatar Jul 30 '20 14:07 repo-alt

This breaks e.g. AE integration NetworkControl.store and probably any other LUA function accepting tables

repo-alt avatar Jul 30 '20 15:07 repo-alt

If the issue cannot be resolved via conventional means, may I suggest an ASM class transformer?

repo-alt avatar Aug 16 '20 09:08 repo-alt

updating jnlua breaks our eris support. using a asm conversion may be the smart thing to do. focusing on different issues/features now

payonel avatar May 11 '21 01:05 payonel

I tried to ASM patch DefaultConverter.convertLuaValue but lua_next() still throws on integer conversion. (btw. there is no lua_isinteger in this version of JNLua, so I had to use toIntegerX) Unfortunately lua_next is not very informative about what it doesn't like there. Also, what is eris?

repo-alt avatar May 11 '21 21:05 repo-alt

eris is our lua-serializtion library, the thing we use to persist the lua state in-game https://github.com/fnuecke/eris

payonel avatar May 11 '21 22:05 payonel

So, it looks like 5.3 should not have been made default architecture, if one of it's key features (native integers) cannot be fully supported.

repo-alt avatar May 11 '21 22:05 repo-alt

i somewhat, maybe mostly, agree with you. but this issue only breaks passing some table data over our java api. user scripts in-game can use lua 5.3 just fine

payonel avatar May 11 '21 23:05 payonel

As far as I see Sangar still supports https://github.com/fnuecke/eris, so, why can't he be contacted about JNLua?

repo-alt avatar Jun 11 '22 08:06 repo-alt

Reopened on request from GT:NH.

asiekierka avatar Jun 11 '22 11:06 asiekierka

Does this still occur after https://github.com/MightyPirates/OpenComputers/commit/ac4d93589ab9c666979bbfda818cad701b617a47 ?

asiekierka avatar Sep 04 '22 19:09 asiekierka

ok, I finally tested and it works fine now, thanks!

repo-alt avatar Dec 03 '22 17:12 repo-alt