mirror of
https://github.com/cimgui/cimgui.git
synced 2026-04-22 03:31:17 +01:00
simplify generator.lua for modules
This commit is contained in:
@@ -463,7 +463,7 @@ local function parseItems(txt,linenumdict, itparent, dumpit)
|
|||||||
--take locat from parent
|
--take locat from parent
|
||||||
if itparent and itparent.locat then
|
if itparent and itparent.locat then
|
||||||
loca = itparent.locat
|
loca = itparent.locat
|
||||||
print("parent loca",string.format("%q , %q ",itemold,itemfirstline),#itemfirstline,loca)
|
--print("parent loca",string.format("%q , %q ",itemold,itemfirstline),#itemfirstline,loca)
|
||||||
else
|
else
|
||||||
loca = 0
|
loca = 0
|
||||||
print("not loca",string.format("%q , %q ",itemold,itemfirstline),#itemfirstline,loca)
|
print("not loca",string.format("%q , %q ",itemold,itemfirstline),#itemfirstline,loca)
|
||||||
@@ -1157,6 +1157,7 @@ local function get_nonPOD(FP)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
FP.structs_and_enums_table.nonPOD = nonPOD
|
FP.structs_and_enums_table.nonPOD = nonPOD
|
||||||
|
M.prtable("nonPOD",nonPOD)
|
||||||
return nonPOD
|
return nonPOD
|
||||||
end
|
end
|
||||||
local function recur_calc_depth(FP, structs, k,n)
|
local function recur_calc_depth(FP, structs, k,n)
|
||||||
@@ -1722,6 +1723,12 @@ local function save_output(self)
|
|||||||
save_data("./output/structs_and_enums.json",json.encode(self.structs_and_enums_table))
|
save_data("./output/structs_and_enums.json",json.encode(self.structs_and_enums_table))
|
||||||
save_data("./output/typedefs_dict.json",json.encode(self.typedefs_dict))
|
save_data("./output/typedefs_dict.json",json.encode(self.typedefs_dict))
|
||||||
save_data("./output/constants.json",json.encode(self.constants))
|
save_data("./output/constants.json",json.encode(self.constants))
|
||||||
|
|
||||||
|
local modulename = self.modulename
|
||||||
|
copyfile("./output/"..modulename..".h", "../"..modulename..".h")
|
||||||
|
copyfile("./output/"..modulename..".cpp", "../"..modulename..".cpp")
|
||||||
|
os.remove("./output/"..modulename..".h")
|
||||||
|
os.remove("./output/"..modulename..".cpp")
|
||||||
end
|
end
|
||||||
-------------
|
-------------
|
||||||
local numerr = 0 --for popen error file
|
local numerr = 0 --for popen error file
|
||||||
@@ -3037,6 +3044,30 @@ function M.Parser()
|
|||||||
end
|
end
|
||||||
return table.concat(precode).."\ntypedef struct "..ttype.."_"..newte.." {"..table.concat(code).."} "..ttype.."_"..newte..";\n"
|
return table.concat(precode).."\ntypedef struct "..ttype.."_"..newte.." {"..table.concat(code).."} "..ttype.."_"..newte..";\n"
|
||||||
end
|
end
|
||||||
|
--generate cimgui.cpp cimgui.h
|
||||||
|
function par:cimgui_generation( cimgui_header)
|
||||||
|
local name = self.modulename
|
||||||
|
local hstrfile = read_data("./"..name.."_template.h")
|
||||||
|
|
||||||
|
local outpre,outpost = self.structs_and_enums[1], self.structs_and_enums[2]
|
||||||
|
local tdt = self:generate_templates()
|
||||||
|
local cstructsstr = outpre..tdt..outpost
|
||||||
|
|
||||||
|
hstrfile = hstrfile:gsub([[#include "imgui_structs%.h"]],cstructsstr)
|
||||||
|
hstrfile = hstrfile:gsub([[PLACE_STRUCTS_C]],self:gen_structs_c())
|
||||||
|
local cfuncsstr = M.func_header_generate(self)
|
||||||
|
hstrfile = hstrfile:gsub([[#include "auto_funcs%.h"]],cfuncsstr)
|
||||||
|
save_data("./output/"..name..".h",cimgui_header,hstrfile)
|
||||||
|
|
||||||
|
--merge it in cimplot_template.cpp to cimplot.cpp
|
||||||
|
local cimplem = M.func_implementation(self)
|
||||||
|
|
||||||
|
local hstrfile = read_data("./"..name.."_template.cpp")
|
||||||
|
|
||||||
|
hstrfile = hstrfile:gsub([[#include "auto_funcs%.cpp"]],cimplem)
|
||||||
|
save_data("./output/"..name..".cpp",cimgui_header,hstrfile)
|
||||||
|
|
||||||
|
end
|
||||||
return par
|
return par
|
||||||
end
|
end
|
||||||
-- more compact serialization
|
-- more compact serialization
|
||||||
@@ -3570,6 +3601,55 @@ local function func_header_generate(FP)
|
|||||||
end
|
end
|
||||||
|
|
||||||
M.func_header_generate = func_header_generate
|
M.func_header_generate = func_header_generate
|
||||||
|
function M.GetScriptArgs(defines,...)
|
||||||
|
assert(_VERSION=='Lua 5.1',"Must use LuaJIT")
|
||||||
|
assert(bit,"Must use LuaJIT")
|
||||||
|
local script_args = {...}
|
||||||
|
local COMPILER = script_args[1]
|
||||||
|
local INTERNAL_GENERATION = (script_args[2] and script_args[2]:match("internal")) and true or false
|
||||||
|
local COMMENTS_GENERATION = (script_args[2] and script_args[2]:match("comments")) and true or false
|
||||||
|
|
||||||
|
local predefine = COMPILER == "cl" and "/D" or "-D"
|
||||||
|
local defines_str = ""
|
||||||
|
for i,define in ipairs(defines) do
|
||||||
|
defines_str = defines_str .. " "..predefine..define
|
||||||
|
end
|
||||||
|
|
||||||
|
local CPRE,CTEST
|
||||||
|
if COMPILER == "gcc" or COMPILER == "clang" or COMPILER == "g++" then
|
||||||
|
CPRE = COMPILER..[[ -E -dD -std=c++17 -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_API="" ]]..defines_str ---std=c++17
|
||||||
|
CTEST = COMPILER.." --version"
|
||||||
|
elseif COMPILER == "cl" then
|
||||||
|
CPRE = COMPILER..[[ /E /d1PP /DIMGUI_DISABLE_OBSOLETE_FUNCTIONS /DIMGUI_API="" ]]..defines_str
|
||||||
|
CTEST = COMPILER
|
||||||
|
else
|
||||||
|
print("Working without compiler ")
|
||||||
|
error("cant work with "..COMPILER.." compiler")
|
||||||
|
end
|
||||||
|
--test compiler present
|
||||||
|
local HAVE_COMPILER = false
|
||||||
|
|
||||||
|
local pipe,err = io.popen(CTEST,"r")
|
||||||
|
if pipe then
|
||||||
|
local str = pipe:read"*a"
|
||||||
|
print(str)
|
||||||
|
pipe:close()
|
||||||
|
if str=="" then
|
||||||
|
HAVE_COMPILER = false
|
||||||
|
else
|
||||||
|
HAVE_COMPILER = true
|
||||||
|
end
|
||||||
|
else
|
||||||
|
HAVE_COMPILER = false
|
||||||
|
print(err)
|
||||||
|
end
|
||||||
|
assert(HAVE_COMPILER,"gcc, clang or cl needed to run script")
|
||||||
|
|
||||||
|
print("HAVE_COMPILER",HAVE_COMPILER)
|
||||||
|
print("INTERNAL_GENERATION",INTERNAL_GENERATION)
|
||||||
|
|
||||||
|
return COMPILER, CPRE, INTERNAL_GENERATION,COMMENTS_GENERATION
|
||||||
|
end
|
||||||
--[=[
|
--[=[
|
||||||
-- tests
|
-- tests
|
||||||
|
|
||||||
|
|||||||
@@ -379,16 +379,15 @@ end
|
|||||||
local function parseImGuiHeader(header,names)
|
local function parseImGuiHeader(header,names)
|
||||||
--prepare parser
|
--prepare parser
|
||||||
local parser = cpp2ffi.Parser()
|
local parser = cpp2ffi.Parser()
|
||||||
|
parser.modulename = "cimgui"
|
||||||
parser.getCname = function(stname,funcname,namespace)
|
parser.getCname = function(stname,funcname,namespace)
|
||||||
local pre = (stname == "") and (namespace and (namespace=="ImGui" and "ig" or namespace.."_") or "ig") or stname.."_"
|
local pre = (stname == "") and (namespace and (namespace=="ImGui" and "ig" or namespace.."_") or "ig") or stname.."_"
|
||||||
return pre..funcname
|
return pre..funcname
|
||||||
end
|
end
|
||||||
parser.cname_overloads = cimgui_overloads
|
parser.cname_overloads = cimgui_overloads
|
||||||
--parser.manuals = cimgui_manuals
|
|
||||||
parser:set_manuals(cimgui_manuals, "cimgui")
|
parser:set_manuals(cimgui_manuals, "cimgui")
|
||||||
parser.skipped = cimgui_skipped
|
parser.skipped = cimgui_skipped
|
||||||
parser.UDTs = {"ImVec2","ImVec4","ImColor","ImRect"}
|
--parser.UDTs = {"ImVec2","ImVec4","ImColor","ImRect"}
|
||||||
--parser.gen_template_typedef = gen_template_typedef --use auto
|
--parser.gen_template_typedef = gen_template_typedef --use auto
|
||||||
parser.COMMENTS_GENERATION = COMMENTS_GENERATION
|
parser.COMMENTS_GENERATION = COMMENTS_GENERATION
|
||||||
parser.CONSTRUCTORS_GENERATION = CONSTRUCTORS_GENERATION
|
parser.CONSTRUCTORS_GENERATION = CONSTRUCTORS_GENERATION
|
||||||
@@ -547,9 +546,5 @@ if parser2 then
|
|||||||
save_data("./output/impl_definitions.json",json.encode(json_prepare(parser2.defsT),{dict_on_empty={defaults=true}}))
|
save_data("./output/impl_definitions.json",json.encode(json_prepare(parser2.defsT),{dict_on_empty={defaults=true}}))
|
||||||
end
|
end
|
||||||
--]]
|
--]]
|
||||||
-------------------copy C files to repo root
|
|
||||||
copyfile("./output/cimgui.h", "../cimgui.h")
|
|
||||||
copyfile("./output/cimgui.cpp", "../cimgui.cpp")
|
|
||||||
os.remove("./output/cimgui.h")
|
|
||||||
os.remove("./output/cimgui.cpp")
|
|
||||||
print"all done!!"
|
print"all done!!"
|
||||||
|
|||||||
Reference in New Issue
Block a user