Created
June 7, 2017 06:46
-
-
Save ibilon/dcdedad85ab249560bab281564997bd1 to your computer and use it in GitHub Desktop.
Wrapper around lua.Table with from function for array and map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package luautils; | |
import lua.Lua; | |
import lua.Table in LuaTable; | |
abstract Table<K, V> (LuaTable<K, V>) from LuaTable<K, V> | |
{ | |
function new (table:LuaTable<K, V>) this = table; | |
@:from static function fromMap<K, V> (map:Map<K, V>) : Table<K, V> | |
{ | |
var table = LuaTable.create({}); | |
for (k in map.keys()) | |
{ | |
Lua.rawset(table, k, map[k]); | |
} | |
return new Table(table); | |
} | |
@:from static function fromArray<T> (arr:Array<T>) : Table<Int, T> | |
{ | |
var table = LuaTable.create({}); | |
for (i in 0...arr.length) | |
{ | |
LuaTable.insert(table, i, arr[i]); | |
} | |
return new Table(table); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment