ScriptUtils.java 632 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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());
	}
}