Is it possible to push a function as a property in Lua?
Right now, I can have Get/Set functions by pushing them as fields like so:
lua_pushcfunction(L,L_Getter);
lua_setfield(L, -2, "GetValue");
lua_pushcfunction(L,L_Setter);
lua_setfield(L, -2, "SetValue");
And calling them in Lua like so:
MyObject:SetValue("NewValue")
Is it possible to push a property that's mapped to a C function without metatables? I could map __index
and __newindex
in metatable to a custom function but I was wondering if there is an easier way. Ultimately, I want the following syntax without metatables:
MyObject.CValue = 1
print(MyObject.CValue)
Is this possible without __index
and __newindex
?
MyObject
is a table. – lhffunction: 00XXXXXX
which makes sense since that field is mapped to a function. – Grapes__index
to various fields of a userdata. – Grapes