'Can you do pointer-like behaviour in Moonsharp?

        public void luatest()
        {
            string raw = @"
somevar = nil

function assign(arg)
    somevar = arg
end

function check()
    Debug.Print(tostring(somevar))
end
";
            MoonSharp.Interpreter.Script script = new MoonSharp.Interpreter.Script();
            script.Globals["Debug"] = new ScriptDebug(s => Debug.Log(s));
            script.DoString(raw);

            Item item = new Item(0, "Axe", "OneHandedAxe"); //This will print "Created item"
            script.Call(script.Globals["assign"], item);
            script.Call(script.Globals["check"]); //This will print "Axe : OneHandedAxe"
            item = null;
            script.Call(script.Globals["check"]);
        }

Is there any way I could make variables (reference types) null when all references to them in C# code are gone? In this example : I would like "somevar" to be nil after I set the item to null.

Console output



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source