I want to load data written in a variant of lua (eyeonScript). However, the data is peppered with references to initialization functions that are not in plain lua:
Redden = BrightnessCo开发者_如何学编程ntrast {
Inputs = {
Red = Input {
Value = 0,
},
},
}
Standard lua gives "attempt to call a nil value" or "unexpected symbol" errors. Is there any way to catch these and pass it to some sort of generic initializer?
I want to wind up with a nested table data structure.
Thanks!
Set an __index
metamethod for the table of globals. For instance, so that undefined functions behave like the identity:
setmetatable(_G,{__index=function (n)
return function (x) return x end
end})
Here is another trick: set __call for nil, but you need to do it in C or using the debug library. The advantage of this trick is that it only handles calls to undefined functions:
debug.setmetatable(nil,{__call=function (x,v) return v end})
精彩评论