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

Support table constructor/object initializer on created CLR objects #306

Open
SmilingCatEntertainment opened this issue Jun 23, 2022 · 0 comments

Comments

@SmilingCatEntertainment
Copy link

SmilingCatEntertainment commented Jun 23, 2022

C# supports an object initializer syntax on construction like so:
var myObj = new MyClass() {someOptionalProperty="value"};

Likewise Lua standard 16.1 supports this on its native values via OO syntactic sugar:
myLuaObj = MyLuaPrototype:new{someOptionalProperty="value"};

However, MoonSharp does not support this syntactic sugar when creating CLR objects:
myClrObj = MyClass:__new{someOptionalProperty="value"}; --Expected: myClrObj.someOptionalProperty == "value", actual: myClrObj.someOptionalProperty == nil

It would be nice if creation of CLR objects from Lua respected the same initialization/table constructor syntax available to Lua objects. Bonus if the "__new" CLR constructor method name could be changed/aliased to "new" to be consistent with the rest of the Lua world as well.

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

1 participant