Fix bad casting exceptions with scene garbages objects

This commit is contained in:
Melledy
2022-05-19 02:28:25 -07:00
parent 0dac404f0d
commit 8c860308ba
5 changed files with 60 additions and 5 deletions

View File

@@ -0,0 +1,28 @@
package emu.grasscutter.scripts;
import java.util.HashMap;
import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue;
import emu.grasscutter.Grasscutter;
public class ScriptUtils {
public static HashMap<Object, Object> toMap(LuaTable table) {
HashMap<Object, Object> map = new HashMap<>();
LuaValue[] rootKeys = table.keys();
for (LuaValue k : rootKeys) {
if (table.get(k).istable()) {
map.put(k, toMap(table.get(k).checktable()));
} else {
map.put(k, table.get(k));
}
}
return map;
}
public static void print(LuaTable table) {
Grasscutter.getLogger().info(toMap(table).toString());
}
}