Configuration Lua特定于域的配置帮助
我有5000个数据项定义配置,我们希望其设计如下:Configuration Lua特定于域的配置帮助,configuration,lua,dsl,Configuration,Lua,Dsl,我有5000个数据项定义配置,我们希望其设计如下: -- 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, <<
-- 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>>
}
--设备的名称
变量名{
类型=浮动,
长度=20,
}
--自上次启动以来运行的设备经过的时间
可变启动时间{
类型=整数,
}
我将从使用不同通信协议的设备中读取“Name”、“BootTime”的值,其中我们使用上述定义的属性
我希望变量也具有前置处理器和后置处理器函数的属性
如果您可以舍弃关键字
变量
,那么代码就是Lua,您只需要一点支持代码(一些\uu索引
元方法)
如果您想保留关键字
VARIABLE
,那么您给出的语法不再是普通的Lua,而是如果您可以使用VARIABLE.BootTime
或VARIABLE“BootTime”
或VARIABLE[BootTime]
的话,那么它就是普通的Lua,可以与合适的元方法一起使用。谢谢您的回答。如果我需要使用变量,处理它的最佳方法是什么?和VARIABLE一样,我还有其他一组专门的数据类型。
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)