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 :: definitions.lua for function definitions
:: structs_and_enums.lua with struct and enum information-definitions :: structs_and_enums.lua with struct and enum information-definitions
:: impl_definitions.lua for implementation function 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 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 ::process files
:: arg[1] true=use gcc false=dont use gcc :: arg[1..n] name of implementations to generate
:: arg[2..] name of implementation to generate luajit.exe ./generator.lua glfw opengl3 opengl2 sdl
luajit.exe ./generator.lua false glfw opengl3 opengl2 sdl
::copy cimgui.h and cimgui.cpp ::copy cimgui.h and cimgui.cpp
copy .\cimgui.h ..\cimgui.h copy .\generated\cimgui.h ..\cimgui.h
copy .\cimgui.cpp ..\cimgui.cpp copy .\generated\cimgui.cpp ..\cimgui.cpp
::leave console open ::leave console open
cmd /k cmd /k

View File

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