You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I might just be misunderstanding something. My Lua is extremely rusty, and my experience with NLua is virtually zero.
This code doesn't have the behavior I'd expect:
using System.Dynamic;using NLua;Luastate=new();dynamicx=new ExpandoObject();
x.a =5;
state["x"]=x;// Run embedded Lua.
state.DoString("""
print(x.a)
x.a = 10
print(x.a)
""");
This makes a dynamic/ExpandoObject in C# and adds it as a (global?) variable. Lua is able to see x.a (the print(x.a) shows 5). But on the assignment line, with x.a = 10, I get the following error:
NLua.Exceptions.LuaScriptException: 'field or property 'a' does not exist'
It seems like it is available for reading but not writing.
This variation worked fine, which makes me think I'm not just making a Lua syntax error.
using NLua;Luastate=new();
state.DoString("""
x = {}
print(x.a)
x.a = 10
print(x.a)
""");
This displays nil at first, and then 10, as I'd expect.
I can't tell if this is a bug or if I'm just missing something obvious. I'd expect that I could send an ExpandoObject over to Lua and have Lua be able to modify its values, not just see the current ones.
I'd love some advice or guidance from people more experienced with Lua and NLua.
The text was updated successfully, but these errors were encountered:
I am not sure what you trying to achieve. But NLua will try to use reflection. I don't think it will work with ExpandObject. But why not use a Lua object directly ?
Because I need the interop. The object must also be useable in C#, and actually begins life on the C# side. ExpandoObject definitely feels easy on the C# side, and something that should just work on the Lua side, since Lua is a dynamically typed language. This paradigm works fine in IronPython, for what it's worth. So there isn't some platform limitation or anything.
I see. I guess it would be doable if we can dynamically invoke properties/methods in the dynamic object. NLua will try to reflect over the CLR object directly, but in theory it could be fixed changing NLua to check if is a dynamic object.
As workaround I guess you could invoke a helper method and pass the name of the property and the value to C# and just set to the ExpandoObject using the the IDictionary interface.
I might just be misunderstanding something. My Lua is extremely rusty, and my experience with NLua is virtually zero.
This code doesn't have the behavior I'd expect:
This makes a dynamic/
ExpandoObject
in C# and adds it as a (global?) variable. Lua is able to seex.a
(theprint(x.a)
shows5
). But on the assignment line, withx.a = 10
, I get the following error:It seems like it is available for reading but not writing.
This variation worked fine, which makes me think I'm not just making a Lua syntax error.
This displays
nil
at first, and then10
, as I'd expect.I can't tell if this is a bug or if I'm just missing something obvious. I'd expect that I could send an ExpandoObject over to Lua and have Lua be able to modify its values, not just see the current ones.
I'd love some advice or guidance from people more experienced with Lua and NLua.
The text was updated successfully, but these errors were encountered: