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

Working with tables in LuaJava #103

Closed slava110 closed 1 year ago

slava110 commented 1 year ago

Hi. How to properly work with tables in LuaJava?

Case 1:

For example, I want to get all keys or values of certain table. In vanilla Lua you can do it using pairs function to iterate over table. How to properly iterate over table on Java side though? Do I need to use run for that? Maybe there's more elegant solution? Also maybe it's possible to get keys of table on C side properly without any iteration at all?

Case 2:

If I want to insert into table or sort table in Lua I can use table.sort and table.insert. But there's no hooks to do that from Java side. Should I use run in this case too?

osp54 commented 1 year ago
for (Object entry : lua.toList(index)) {
    workWithEntry();
}