Lua domain specific configuration help – Education Career Blog

I have 5000 data item definition configuration which we are expecting to be designed like,

-- Name of the device
VARIABLE Name { 
   type=Float,
   length=20,
   <<few more definition here>>
}

-- The device running elapsed time since its last boot
VARIABLE BootTime {
   type=Integer,       
   <<few more definition here>>
}

I will be reading the value of “Name”, “BootTime” from a device using diffent communication protocol where we use the above property defined.

I want the VARIABLE to also have properties to pre_processor and post_processor functions.

  1. How to define the structure like this in Lua? If this strcuture is not possible, what is the closet structure possible in Lua

  2. I want to overload operator for this Variable definitions so that I can do,

    I can configure BootTime = 23456789 or
    Do arithmetic like BootTime + 100 (milliseconds)
    Or comparison like if BootTime > 23456789 then do something

,

If you can ditch the keyword VARIABLE then the code is Lua and you only need a little support code (some __index metamethod magic).

Integer="Integer"
setmetatable(_G,
        { __index = function(t,n)
                        return function (x) _Gn=x.value end
                end })
BootTime {
        type=Integer,
        value=10000
}
print(BootTime+2345)

If you want to keep the keyword VARIABLE then the syntax you gave is no longer plain Lua but if you can live with VARIABLE.BootTime or VARIABLE"BootTime" or VARIABLEBootTimethen it is plain Lua and can be made to work with suitable metamethods.

Leave a Comment