My problem is that haxe doesn't want to compile a following snippet to lua target. It complains about:
Main.hx:7: characters 11-17 : String should be Int
import lua.Table;
class Main {
static public function my_test(): Table<String, Int>
{
var t: Table<String, Int> = Table.create();
t["test"] = 1; # Heres the problem
return t;
}
static public function main(): Void
{
var x = my_test();
trace(x);
}
}
If I change the problematic line to:
t[1] = 1; It strangely doesn't complain which seems not logical to me as it's a wrong type in my understanding.
If I put $type(t) somewhere into the snippet above, it correctly identifies it as lua.Table<String, Int>.
I looked into source of std/lua/Table.hx and based on some code there I used untyped keyword in my snippet: t[untyped "test"] = 1; only then it generates desired lua code that executes successfully:
Main.my_test = function()
local t = ({});
t.test = 1;
do return t end;
end
Although I expected something like:
Main.my_test = function()
local t = {};
t["test"] = 1;
do return t end;
end
So, why I have to use this keyword?
$ haxe --version
4.2.1+bf9ff69
# I compile with
$ haxe -D lua-vanilla --main Main --lua Main.lua