NLua / NLua

Bridge between Lua and the .NET.
http://nlua.org
MIT License
2.04k stars 309 forks source link

Unable to set value in struct #532

Open DamienIsPoggers opened 5 months ago

DamienIsPoggers commented 5 months ago

I'm currently writing a game that uses lua as a scripting language for characters. While trying to do something I noticed that it isn't setting to values inside structs.

For my base actor class I have a System.Numerics.Vector3 and when I try to get it it works. For example this would work

using System.Numerics;
using NLua;

internal class Actor
{
    public Vector3 position = Vector3.Zero;
    public Lua luaState = new Lua();

    public Actor()
    {
        luaState.DoString(@"
        function PrintPos(actor)
            print(actor.position.X)
            end
        ");

         luaState.GetFunction("PrintPos").Call(this);
        //prints 0.0
    }
}

but for whatever reason this wouldn't work

using System.Numerics;
using NLua;

internal class Actor
{
    public Vector3 position = Vector3.Zero;
    public Lua luaState = new Lua();

    public Actor()
    {
        luaState.DoString(@"
        function PrintPos(actor)
            print(actor.position.X)
            end
        ");

        luaState.DoString(@"
        function SetPos(actor)
            actor.position.X = 2.5
            end
        ");

         luaState.GetFunction("PrintPos").Call(this);
        //prints 0.0
         luaState.GetFunction("SetPos").Call(this);
         luaState.GetFunction("PrintPos").Call(this);
        //prints 0.0
    }
}

Im pretty sure this might be a bug of some sort, either that or im doing something wrong, which if I am could i get some help?

frankhale commented 3 months ago

This closed issue looks relevant to what you are trying to do:

https://github.com/NLua/NLua/issues/384