1
0
mirror of https://github.com/elua/elua.git synced 2025-01-08 20:56:17 +08:00
elua/config/generators.lua
Bogdan Marinescu 5ce6a8aef6 Multiple changes
- more build configuration attributes (allocator, target)
- more sanity checks
- more color in the builder
- 'romfs' is now a separate builder target, not a function being called separately
- added mappings for the configurator attributes
2012-07-01 20:59:55 +03:00

41 lines
1.1 KiB
Lua

-- Code generators for various attributes and other constructs
module( ..., package.seeall )
local sf = string.format
local MACRO_DEF_POS = 41
-- Formatted print for "#define"
function print_define( k, v )
local s = sf( "#define %s", k )
if v then
if #s < MACRO_DEF_POS then s = s .. string.rep( ' ', MACRO_DEF_POS - #s ) end
else
v = ''
end
s = s .. tostring( v ) .. "\n"
return s
end
-- Simple generator for an attribute
function simple_gen( attrname, conf, gentable )
if gentable[ attrname ] then return '' end
if not conf[ attrname ] then return '' end
local adesc, aval = conf[ attrname ].desc, conf[ attrname ].value
gentable[ attrname ] = true
if adesc.is_ip then -- special generation for this one
local s = ''
for i = 1, 4 do
s = s .. print_define( sf( "%s%d", attrname, i - 1 ), aval[ i ] )
end
return s
end
if adesc.mapping then aval = adesc.mapping[ aval ] end
if adesc.is_array then
-- The element is an array. The default is to define its value as { elements }
aval = "{ " .. table.concat( aval, "," ) .. " }"
end
return print_define( attrname, tostring( aval ) )
end