gudzpoz / luajava

Lua for Java on Windows, Mac OS X, Linux, Android. 5.1, 5.2, 5.3, 5.4, LuaJ or LuaJIT.
https://gudzpoz.github.io/luajava/
Other
141 stars 17 forks source link

Conversion from lua table to java map use wrong index #127

Closed MaxThlon closed 9 months ago

MaxThlon commented 10 months ago

Hello. Conversion from lua table to java map use wrong index to call C.lua_next(L, -2) in AbstractLua.java line 384 C.lua_next(L, -2) is missing index, one solution is / Use positive index or values under LUA_REGISTRYINDEX(-10000), or decrement negative index / C.lua_next(L, ((index > 0) || (index < -9999))? index : (index -1))

or the other solution is to pushValue(index) when stack is at the same state and re pushValue(...) for the lua_next call.

Otherwise it's work pretty well, cool project, thanks for the hard work.

To Reproduce L.createTable(0, 2); L.push("AA"); L.setField(-2, "A"); L.pushNil(); / dumb value to fill the stack / Map<?, ?> map = L.toMap(-2); / will crash / assert(!map.isEmpty()); / will fail / L.pop(2)

Platform:

gudzpoz commented 9 months ago

Thank you for reporting! A new version 3.5.0 with the fix should have been published on Maven Central.