[JW Lua] JW Lua constant namespaces

Jari Williamsson jari.williamsson at mailbox.swipnet.se
Thu Sep 3 18:12:41 CEST 2015


Hello All!

Attached is a script that converts the JW Lua constant names into 
namespaces (based on Thomas' suggestion regarding more Lua-like constant 
handling). For example, all NOTE_* constants become a NOTE namespace 
containing all the subconstants. The standard JW Lua constants are not 
deleted.

Try it out.


Best regards,

Jari Williamsson
-------------- next part --------------
local function ProcessConstantName(constname)
    local pos = string.find(constname, "_")
    if pos == nil then return end
    local namespace = string.sub(constname, 1, pos-1)    
    local varname = string.sub(constname, pos+1)
    local value = _G.finale[constname]    
    if (_G[namespace] == nil) then
        _G[namespace] = {}
    end
    _G[namespace][varname] = value
end

-- Search for constants
for k,v in pairs(_G.finale) do
    if string.find(k, "__propget") == 1 and (type(v) == "table") then
        for k1, v1 in pairs(v) do            
             ProcessConstantName(k1)
        end
    end
end


More information about the JWLua mailing list