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.42k stars 214 forks source link

Assigning a global inside of a nested table doesn't work #109

Closed jacobdufault closed 9 years ago

jacobdufault commented 9 years ago

Running inside of Unity,

Script script = new Script(CoreModules.Preset_SoftSandbox);

script.Options.DebugPrint = Debug.Log;

script.DoString("top = {}");
script.Globals["top.lower"] = 1;
script.DoString("print(top.lower)");

This should print 1 but instead it prints nil.

I've worked around this issue with

private static void AssignGlobal(Script script, string globalName, object value) {
    script.Globals["_tmp"] = value;
    script.DoString(globalName + " = _tmp ; _tmp = nil");
}
xanathar commented 9 years ago

The behavior is correct and is the same as if you wrote

_ENV["top.lower"]=1

In Lua.

If you want to set a value in a table use

script.Globals["top", "lower"]=1

----- Messaggio originale ----- Da: "Jacob Dufault" notifications@github.com Inviato: ‎30/‎08/‎2015 06:12 A: "xanathar/moonsharp" moonsharp@noreply.github.com Oggetto: [moonsharp] Assigning a global inside of a nested table doesn't work(#109)

Running inside of Unity, Script script = new Script(CoreModules.Preset_SoftSandbox);

script.Options.DebugPrint = Debug.Log;

script.DoString("top = {}"); script.Globals["top.lower"] = 1; script.DoString("print(top.lower)"); This should print 1 but instead it prints nil. I've worked around this issue with private static void AssignGlobal(Script script, string globalName, object value) { script.Globals["_tmp"] = value; script.DoString(globalName + " = _tmp ; _tmp = nil"); }— Reply to this email directly or view it on GitHub.

jacobdufault commented 9 years ago

sg