lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> The same is repeated for all variables. Instead I want the string
> equivalent of variables DeviceParam1, DeviceParam2, DeviceParam3
> handled internally by Lua and assigned to NAME property.

Set up a proxy for _G and set a __newindex for the proxy that does that.
Something  like this:

    local function set(t,k,v)
	    print("SET",k,v,type(v))
	    if type(v)=="table" then v.NAME=k end
	    rawset(t,k,v)
    end
    setmetatable(getfenv(),{__index=_G,__newindex=set})