moonsharp-devs / moonsharp

An interpreter for the Lua language, written entirely in C# for the .NET, Mono, Xamarin and Unity3D platforms, including handy remote debugger facilities.
http://www.moonsharp.org
Other
1.41k stars 213 forks source link

Immediately invoked function expressions #233

Closed Benjamin-Dobell closed 5 years ago

Benjamin-Dobell commented 6 years ago

Moonsharp raises:

attempt to call a no value value

when encountering an immediate invocation of an anonymous function e.g.

(function()
    print('Hi')
end)()

This syntax works in at least the Lua CLI, I'm not sure about other runtimes.

Honestly, it's not a major issue, but I couldn't find this documented anywhere, and it would of course be nice to have more compatibility if possible 😄

Anyway, thanks for all the hard work put into Moonsharp, it's pretty great!

stever commented 5 years ago

I just tried this in the MoonSharp REPL and it works there, as expected prints "Hi".

Benjamin-Dobell commented 5 years ago

@stever Thanks, I just checked this myself and am indeed able to get it working in the REPL (even several versions ago).

I've actually ran into this writing mods for a game for which I don't have the source, so I'm not really able to debug this at present. If I get some time I'll go setup a test project to see if I can reproduce the issue there.

Benjamin-Dobell commented 5 years ago

Okay, I've finally worked out a proper reproduction case for this:

(function()
    print('hi')
end)()
(function()
    print('bye')
end)()

I had some files that were being concatenated such that I ended up with neighbouring IIFEs as above. However, this fails in regular Lua, so isn't a MoonSharp issue. So I'm closing this. Sorry for the confusion!