Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lua] Creating a table without __fields__ #11805

Open
LordMZTE opened this issue Oct 26, 2024 · 1 comment
Open

[lua] Creating a table without __fields__ #11805

LordMZTE opened this issue Oct 26, 2024 · 1 comment

Comments

@LordMZTE
Copy link

LordMZTE commented Oct 26, 2024

I need to call an extern Lua function which expects a table with very specific fields and does not allow any additional fields. I have the function declared as such:

typedef Options = {
    baz:Int,
};

extern class Foo {
    static function bar(opts:Options):Void;
}

When this function is invoked as Foo.bar({ baz: 42; }), this generates some pretty complex Lua code which ends up passing

{
     baz = 42,
     __fields__ = ...
}

It would be great if there was a way to write an expression that results in plain { baz = 42 } in Haxe.

As a workaround, this seems to work:

final x = { baz: 42; }
cast(x, lua.AnyTable).__fields__ = null;
Foo.bar(x);
@jdonaldson
Copy link
Member

There's some helper methods for working with tables : https://api.haxe.org/lua/Table.html

By default anonymous objects include the fields field so that reflection works consistently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants