all output to generated folder and test HAVE_GCC.

cimgui and cimgui_auto versions
This commit is contained in:
sonoro1234
2018-06-27 15:21:48 +02:00
parent 1ee766c0e1
commit 1e5ce71257
6 changed files with 1093 additions and 1088 deletions

File diff suppressed because it is too large Load Diff

978
cimgui.h

File diff suppressed because it is too large Load Diff

View File

@@ -1,20 +1,24 @@
:: this is used to rebuild cimgui.h and cimgui.cpp and must be executed in this directory
:: this script must be executed in this directory
:: all the output goes to generated folder
:: .cpp and .h files:
:: cimgui.h and cimgui.cpp generated without preprocess
:: cimgui_auto.h and cimgui_auto.cpp with gcc preprocess
:: cimgui_impl.h with implementation function cdefs
:: lua and json files:
:: definitions.lua for function definitions
:: structs_and_enums.lua with struct and enum information-definitions
:: impl_definitions.lua for implementation function definitions
:: cimgui_impl.h with implementation function cdefs
:: set your PATH if necessary for LuaJIT or Lua5.1 or luajit with: (for example)
:: set PATH=%PATH%;C:\luaGL;
set PATH=%PATH%;C:\luaGL;C:\mingw32\bin;
::process files
:: arg[1] true=use gcc false=dont use gcc
:: arg[2..] name of implementation to generate
luajit.exe ./generator.lua false glfw opengl3 opengl2 sdl
:: arg[1..n] name of implementations to generate
luajit.exe ./generator.lua glfw opengl3 opengl2 sdl
::copy cimgui.h and cimgui.cpp
copy .\cimgui.h ..\cimgui.h
copy .\cimgui.cpp ..\cimgui.cpp
copy .\generated\cimgui.h ..\cimgui.h
copy .\generated\cimgui.cpp ..\cimgui.cpp
::leave console open
cmd /k

View File

@@ -3,10 +3,28 @@
--expects Lua 5.1 or luajit
--------------------------------------------------------------------------
local script_args = {...}
--test gcc present
local HAVE_GCC
local pipe,err = io.popen("gcc --version","r")
if pipe then
local str = pipe:read"*a"
print(str)
pipe:close()
if str=="" then
HAVE_GCC = false
else
HAVE_GCC = true
end
else
HAVE_GCC = false
print(err)
end
print("HAVE_GCC",HAVE_GCC)
--get implementations
local implementations = {}
for i=2,#script_args do table.insert(implementations,script_args[i]) end
-- first script argument to use gcc or not
local USEGCC = script_args[1] == "true"
for i=1,#script_args do table.insert(implementations,script_args[i]) end
--------------------------------------------------------------------------
--this table has the functions to be skipped in generation
--------------------------------------------------------------------------
@@ -154,9 +172,12 @@ local function serializeTable(name, value, saved)
return table.concat(string_table)
end
local function save_data(filename,data)
local function save_data(filename,...)
local file = io.open(filename,"w")
file:write(data)
for i=1, select('#', ...) do
local data = select(i, ...)
file:write(data)
end
file:close()
end
@@ -165,7 +186,7 @@ local function strip(cad)
end
local function clean_spaces(cad)
cad = strip(cad)
--cad = cad:gsub("%s+","%s") --not more than one space
cad = cad:gsub("%s+"," ") --not more than one space
cad = cad:gsub("%s*([%(%),=])%s*","%1") --not spaces with ( , )
return cad
end
@@ -214,7 +235,7 @@ local function struct_parser()
if in_functionst then
if line:match(function_closing_re) then
in_functionst = false
print("in function:",line)
--print("in function:",line)
end
return
end
@@ -224,7 +245,7 @@ local function struct_parser()
if (line:match(function_re) or line:match(operator_re)) and not line:match("typedef.*%b().*%b().*")
and not line:match(functype_re) then
if not line:match(function_closed_re) then
print("match:",line)
--print("match:",line)
in_functionst = true
end
--else
@@ -453,7 +474,7 @@ local function func_parser()
defT.location = locat
defT.comment = comment
if ret then
defT.ret = ret:gsub("&","*")
defT.ret = clean_spaces(ret:gsub("&","*"))
defT.retref = ret:match("&")
end
defsT[cimguiname][signature] = defT
@@ -592,7 +613,7 @@ local function gen_structs_and_enums_table(cdefs)
end
local function gen_structs_and_enums(cdefs)
local function gen_structs_and_enums(cdefs,addextra)
local function_closing_re = "}"
local namespace_re = "namespace"
local in_namespace = false
@@ -605,8 +626,8 @@ local function gen_structs_and_enums(cdefs)
local typedefs_table = {}
local outtab = {}
-- Output the file
table.insert(outtab,"/////////////// BEGIN AUTOGENERATED SEGMENT\n")
if not USEGCC then
--table.insert(outtab,"/////////////// BEGIN AUTOGENERATED SEGMENT\n")
if addextra then
table.insert(outtab,[[typedef unsigned short ImDrawIdx;]])
table.insert(outtab,[[typedef void* ImTextureID;]])
end
@@ -698,11 +719,13 @@ typedef struct ImVector ImVector;]])
end
end
table.insert(outtab,"//////////////// END AUTOGENERATED SEGMENT \n")
--table.insert(outtab,"//////////////// END AUTOGENERATED SEGMENT \n")
for i,l in ipairs(typedefs_table) do
table.insert(outtab,2,l)
end
return outtab
local cstructsstr = table.concat(outtab)
cstructsstr = cstructsstr:gsub("\n+","\n") --several empty lines to one empty line
return cstructsstr
end
local function func_header_impl_generate(FP)
@@ -725,8 +748,9 @@ local function func_header_impl_generate(FP)
table.insert(outtab,t.comment:gsub("%%","%%%%").."\n")-- %% substitution for gsub
end
end
--hfile:close()
return outtab
local cfuncsstr = table.concat(outtab)
cfuncsstr = cfuncsstr:gsub("\n+","\n") --several empty lines to one empty line
return cfuncsstr
end
local function func_header_generate(FP)
@@ -765,8 +789,10 @@ local function func_header_generate(FP)
table.insert(outtab,t.comment:gsub("%%","%%%%").."\n")-- %% substitution for gsub
end
end
--hfile:close()
return outtab
local cfuncsstr = table.concat(outtab)
cfuncsstr = cfuncsstr:gsub("\n+","\n") --several empty lines to one empty line
return cfuncsstr
end
local function func_implementation(FP)
@@ -828,84 +854,84 @@ local function func_implementation(FP)
until true
end
--cppfile:close()
return outtab
return table.concat(outtab)
end
--generate cimgui.cpp cimgui.h and auto versions depending on postfix
local function cimgui_generation(postfix,STP,FP)
--merge it in cimgui_template.h to cimgui.h
local hfile = io.open("./cimgui_template.h","r")
local hstrfile = hfile:read"*a"
hfile:close()
local cstructsstr = gen_structs_and_enums(STP.lines,postfix=="")
hstrfile = hstrfile:gsub([[#include "imgui_structs%.h"]],cstructsstr)
local cfuncsstr = func_header_generate(FP)
hstrfile = hstrfile:gsub([[#include "auto_funcs%.h"]],cfuncsstr)
save_data("./generated/cimgui"..postfix..".h",hstrfile)
--merge it in cimgui_template.cpp to cimgui.cpp
local cimplem = func_implementation(FP)
local hfile = io.open("./cimgui_template.cpp","r")
local hstrfile = hfile:read"*a"
hfile:close()
hstrfile = hstrfile:gsub([[#include "auto_funcs%.cpp"]],cimplem)
hstrfile = hstrfile:gsub([[#include "cimgui%.h"]],[[#include "cimgui]]..postfix..[[.h"]])
save_data("./generated/cimgui"..postfix..".cpp",hstrfile)
end
--------------------------------------------------------
-----------------------------do it----------------------
--------------------------------------------------------
print("USEGCC",USEGCC)
local pipe,err
if USEGCC then
pipe,err = io.popen([[gcc -E -C -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_API="" -DIMGUI_IMPL_API="" ../imgui/imgui.h]],"r")
if not pipe then
error("could not execute gcc "..err)
end
else
pipe,err = io.open("../imgui/imgui.h","r")
if not pipe then
error("could not execute gcc "..err)
end
--first without gcc
local pipe,err = io.open("../imgui/imgui.h","r")
if not pipe then
error("could not open file:"..err)
end
print"goint to iterate"
local STP = struct_parser()
local FP = func_parser()
local iterator = (USEGCC and location) or filelines
for line in iterator(pipe,{"imgui"}) do
for line in filelines(pipe) do
local line, comment = split_comment(line)
STP.insert(line,comment)
FP.insert(line,comment)
end
pipe:close()
--output after insert
-- local hfile = io.open("./outstructs.h","w")
-- hfile:write(table.concat(STP.lines,"\n"))
-- hfile:close()
--do return end
FP:compute_overloads()
cimgui_generation("",STP,FP)
local cstructs = gen_structs_and_enums(STP.lines)
local cfuncs = func_header_generate(FP)
--then gcc
if HAVE_GCC then
local pipe,err = io.popen([[gcc -E -C -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_API="" -DIMGUI_IMPL_API="" ../imgui/imgui.h]],"r")
--merge it in cimgui_template.h to cimgui.h
local hfile = io.open("./cimgui_template.h","r")
local hstrfile = hfile:read"*a"
hfile:close()
local cstructsstr = table.concat(cstructs)
cstructsstr = cstructsstr:gsub("\n+","\n") --several empty lines to one empty line
hstrfile = hstrfile:gsub([[#include "imgui_structs%.h"]],cstructsstr)
local cfuncsstr = table.concat(cfuncs)
cfuncsstr = cfuncsstr:gsub("\n+","\n") --several empty lines to one empty line
hstrfile = hstrfile:gsub([[#include "auto_funcs%.h"]],cfuncsstr)
save_data("./cimgui.h",hstrfile)
if not pipe then
error("could not execute gcc "..err)
end
STP = struct_parser() --overwrite
FP = func_parser() --overwrite
--merge it in cimgui_template.cpp to cimgui.cpp
local cimplem = func_implementation(FP)
local hfile = io.open("./cimgui_template.cpp","r")
local hstrfile = hfile:read"*a"
hfile:close()
hstrfile = hstrfile:gsub([[#include "auto_funcs%.cpp"]],table.concat(cimplem))
save_data("./cimgui.cpp",hstrfile)
for line in location(pipe,{"imgui"}) do
local line, comment = split_comment(line)
STP.insert(line,comment)
FP.insert(line,comment)
end
pipe:close()
FP:compute_overloads()
cimgui_generation("_auto",STP,FP)
end
----------save fundefs in definitions.lua for using in bindings
save_data("./definitions.lua",serializeTable("defs",FP.defsT).."\nreturn defs")
save_data("./generated/definitions.lua",serializeTable("defs",FP.defsT),"\nreturn defs")
----------save struct and enums lua table in structs_and_enums.lua for using in bindings
local structs_and_enums_table = gen_structs_and_enums_table(STP.lines)
save_data("./structs_and_enums.lua",serializeTable("defs",structs_and_enums_table).."\nreturn defs")
save_data("./generated/structs_and_enums.lua",serializeTable("defs",structs_and_enums_table),"\nreturn defs")
--=================================Now implementations
local iFP,iSTP
if #implementations > 0 then
iFP = func_parser()
@@ -915,15 +941,17 @@ if #implementations > 0 then
local source = [[../imgui/examples/imgui_impl_]].. impl .. ".h "
local locati = [[imgui_impl_]].. impl
local pipe,err
if USEGCC then
pipe,err = io.popen([[gcc -E -C -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_API="" -DIMGUI_IMPL_API="" ]] ..source,"r")
if HAVE_GCC then
pipe,err = io.popen([[gcc -E -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_API="" -DIMGUI_IMPL_API="" ]] ..source,"r")
else
pipe,err = io.open(source,"r")
end
if not pipe then
error("could not get file: "..err)
end
local iterator = (HAVE_GCC and location) or filelines
for line,locat in iterator(pipe,{locati}) do
local line, comment = split_comment(line)
iSTP.insert(line,comment)
@@ -933,16 +961,12 @@ if #implementations > 0 then
end
-- save ./cimgui_impl.h
local impl_cfuncs = func_header_impl_generate(iFP)
local impl_cstructs = gen_structs_and_enums(iSTP.lines)
local cstructstr = table.concat(impl_cstructs)
cstructstr = cstructstr:gsub("\n+","\n") --several empty lines to one empty line
local cfuncsstr = table.concat(impl_cfuncs)
cfuncsstr = cfuncsstr:gsub("\n+","\n") --several empty lines to one empty line
save_data("./cimgui_impl.h",cstructstr..cfuncsstr)
local cfuncsstr = func_header_impl_generate(iFP)
local cstructstr = gen_structs_and_enums(iSTP.lines)
save_data("./generated/cimgui_impl.h",cstructstr,cfuncsstr)
----------save fundefs in impl_definitions.lua for using in bindings
save_data("./impl_definitions.lua",serializeTable("defs",iFP.defsT).."\nreturn defs")
save_data("./generated/impl_definitions.lua",serializeTable("defs",iFP.defsT),"\nreturn defs")
end -- #implementations > 0 then
@@ -961,10 +985,10 @@ local function json_prepare(defs)
end
local json = require"json"
save_data("./definitions.json",json.encode(json_prepare(FP.defsT)))
save_data("./structs_and_enums.json",json.encode(structs_and_enums_table))
save_data("./generated/definitions.json",json.encode(json_prepare(FP.defsT)))
save_data("./generated/structs_and_enums.json",json.encode(structs_and_enums_table))
if iFP then
save_data("./impl_definitions.json",json.encode(json_prepare(iFP.defsT)))
save_data("./generated/impl_definitions.json",json.encode(json_prepare(iFP.defsT)))
end
print"all done!!"

View File

@@ -1,21 +0,0 @@
:: this is used to rebuild cimgui.h and cimgui.cpp and must be executed in this directory
:: definitions.lua for function definitions
:: structs_and_enums.lua with struct and enum information-definitions
:: impl_definitions.lua for implementation function definitions
:: cimgui_impl.h with implementation function cdefs
:: set your PATH if necessary for gcc and LuaJIT or Lua 5.1 with: (for example)
:: set PATH=%PATH%;C:\mingw32\bin;C:\luaGL;
::process files
:: arg[1] true=use gcc false=dont use gcc
:: arg[2..] name of implementation to generate
luajit.exe ./generator.lua true glfw opengl3 opengl2 sdl
::copy cimgui.h and cimgui.cpp
copy .\cimgui.h ..\cimgui.h
copy .\cimgui.cpp ..\cimgui.cpp
::leave console open
cmd /k

2
imgui

Submodule imgui updated: f9a5ff7a19...79153cf19f