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

Colon function call syntax doesn't pass parameters properly to C# #149

Closed
nitz opened this issue Sep 2, 2016 · 1 comment
Closed

Colon function call syntax doesn't pass parameters properly to C# #149

nitz opened this issue Sep 2, 2016 · 1 comment

Comments

@nitz
Copy link

nitz commented Sep 2, 2016

Using the colon syntax (eg myTable:Function()) works properly when a function is declared directly in Lua. However, when adding a function to a table via C#, the would be 'self' parameter seems to get dropped.

Unsure if it's related, but I'm using Moonsharp in Unity.
I noticed it on the version I was on (0.9.8.0), but tried using 1.6.0.0 and got the same results too.

// C#
my_table["Foo"] = (Action<Table, string>) ((self, str) => { Debug.Log(str); });
-- Lua
myTable = GetMyCSharpTable()
myTable:Foo("This won't print!")

The above will generate something along the lines of:

(30,14-26): cannot convert a string to a clr type MoonSharp.Interpreter.Table

Changing the C# function declaration to take a DynValue as the first parameter causes my string to end up in that value, and the later string to be null.

Declaring it all in Lua, (like as follows), works fine:

otherTable = {}
function otherTable:Bar(s)
    print("My table: " .. self)
    print(s) 
end

otherTable:Bar("This prints!")
@xanathar
Copy link
Member

xanathar commented Oct 3, 2016

Fixed in 1.7.
Requires an option to be used as this might break compatibility:

S.Options.ColonOperatorClrCallbackBehaviour = ColonOperatorBehaviour.TreatAsDotOnUserData;

@xanathar xanathar closed this as completed Oct 3, 2016
xanathar added a commit that referenced this issue Oct 3, 2016
…o C# #149. Added ColonOperatorClrCallbackBehaviour option.
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