开发者

Lua domain specific configuration help

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 arithme开发者_Go百科tic 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) _G[n]=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 VARIABLE[BootTime]then it is plain Lua and can be made to work with suitable metamethods.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜