I want to pass a Java HashMap to a Lua script from Java code in LuaJ. But all I see is we have chunk.call()
and chunk.invoke()
where we can pass the arguments or array of LuaValue.valueOf()
, which allow us either int, byte, double, string and boolean.
Asked
Active
Viewed 280 times
0
-
Lua doesn't interact with Java. Are you perhaps using LuaJ? – user253751 Apr 05 '22 at 12:55
1 Answers
0
You're looking for LuaValue.tableOf()
to create an empty table. You can then call LuaValue.set
to insert your HashMap entries. Example:
LuaValue table = LuaValue.tableOf();
// assuming map is a HashMap of the "primitive" Lua types valueOf supports
for (Entry e : map.entrySet())
table.set(LuaValue.valueOf(e.getKey()), LuaValue.valueOf(e.getValue()));

Luatic
- 8,513
- 2
- 13
- 34