mirror of
https://github.com/cimgui/cimgui.git
synced 2025-08-11 04:18:29 +01:00
be able to generate without precompiler
This commit is contained in:
@@ -27,9 +27,9 @@ Notes:
|
|||||||
# using generator
|
# using generator
|
||||||
|
|
||||||
* you will need LuaJIT (https://github.com/LuaJIT/LuaJIT.git better 2.1 branch) or precompiled for linux/macOS/windows in https://luapower.com/luajit/download
|
* you will need LuaJIT (https://github.com/LuaJIT/LuaJIT.git better 2.1 branch) or precompiled for linux/macOS/windows in https://luapower.com/luajit/download
|
||||||
* need also gcc compiler for doing preprocessing (In windows MinGW-W64-builds for example) or clang or cl (MSVC)
|
* you can use also a C++ compiler for doing preprocessing: gcc (In windows MinGW-W64-builds for example), clang or cl (MSVC) or not use a compiler (experimental nocompiler option) at all.
|
||||||
* update `imgui` folder to the version you desire.
|
* update `imgui` folder to the version you desire.
|
||||||
* edit `generator/generator.bat` (or make a .sh version and please PR) to choose between gcc, clang or cl. Run it with gcc, clang or cl and LuaJIT on your PATH.
|
* edit `generator/generator.bat` (or make a .sh version and please PR) to choose between gcc, clang, cl or nocompiler. Run it with gcc, clang or cl and LuaJIT on your PATH.
|
||||||
* as a result some files are generated: `cimgui.cpp` and `cimgui.h` for compiling and some lua/json files with information about the binding: `definitions.json` with function info, `structs_and_enums.json` with struct and enum info, `impl_definitions.json` with functions from the implementations info.
|
* as a result some files are generated: `cimgui.cpp` and `cimgui.h` for compiling and some lua/json files with information about the binding: `definitions.json` with function info, `structs_and_enums.json` with struct and enum info, `impl_definitions.json` with functions from the implementations info.
|
||||||
|
|
||||||
# generate binding
|
# generate binding
|
||||||
|
@@ -14,9 +14,9 @@
|
|||||||
:: set PATH=%PATH%;C:\luaGL;C:\i686-7.2.0-release-posix-dwarf-rt_v5-rev1\mingw32\bin;
|
:: set PATH=%PATH%;C:\luaGL;C:\i686-7.2.0-release-posix-dwarf-rt_v5-rev1\mingw32\bin;
|
||||||
:: set PATH=%PATH%;C:\luaGL\sources\luajit-master\luajit-master\bin\mingw32;C:\mingw32\bin;
|
:: set PATH=%PATH%;C:\luaGL\sources\luajit-master\luajit-master\bin\mingw32;C:\mingw32\bin;
|
||||||
::process files
|
::process files
|
||||||
:: arg[1] compiler name gcc, clang or cl
|
:: arg[1] compiler name gcc, clang, cl or nocompiler
|
||||||
:: arg[2..n] name of implementations to generate
|
:: arg[2..n] name of implementations to generate
|
||||||
luajit ./generator.lua "gcc" glfw opengl3 opengl2 sdl
|
luajit ./generator.lua gcc glfw opengl3 opengl2 sdl
|
||||||
|
|
||||||
::leave console open
|
::leave console open
|
||||||
cmd /k
|
cmd /k
|
||||||
|
@@ -14,25 +14,28 @@ elseif COMPILER == "cl" then
|
|||||||
CPRE = COMPILER..[[ /E /DIMGUI_DISABLE_OBSOLETE_FUNCTIONS /DIMGUI_API="" /DIMGUI_IMPL_API="" ]]
|
CPRE = COMPILER..[[ /E /DIMGUI_DISABLE_OBSOLETE_FUNCTIONS /DIMGUI_API="" /DIMGUI_IMPL_API="" ]]
|
||||||
CTEST = COMPILER
|
CTEST = COMPILER
|
||||||
else
|
else
|
||||||
error("not prepared for "..COMPILER)
|
print("Working without compiler ")
|
||||||
end
|
end
|
||||||
--test compiler present
|
--test compiler present
|
||||||
local HAVE_COMPILER
|
local HAVE_COMPILER = false
|
||||||
local pipe,err = io.popen(CTEST,"r")
|
if CTEST then
|
||||||
if pipe then
|
local pipe,err = io.popen(CTEST,"r")
|
||||||
local str = pipe:read"*a"
|
if pipe then
|
||||||
print(str)
|
local str = pipe:read"*a"
|
||||||
pipe:close()
|
print(str)
|
||||||
if str=="" then
|
pipe:close()
|
||||||
HAVE_COMPILER = false
|
if str=="" then
|
||||||
else
|
HAVE_COMPILER = false
|
||||||
HAVE_COMPILER = true
|
else
|
||||||
end
|
HAVE_COMPILER = true
|
||||||
else
|
end
|
||||||
HAVE_COMPILER = false
|
else
|
||||||
print(err)
|
HAVE_COMPILER = false
|
||||||
end
|
print(err)
|
||||||
assert(HAVE_COMPILER,"gcc or clang needed to run script")
|
end
|
||||||
|
assert(HAVE_COMPILER,"gcc, clang or cl needed to run script")
|
||||||
|
end --CTEST
|
||||||
|
|
||||||
print("HAVE_COMPILER",HAVE_COMPILER)
|
print("HAVE_COMPILER",HAVE_COMPILER)
|
||||||
--get implementations
|
--get implementations
|
||||||
local implementations = {}
|
local implementations = {}
|
||||||
@@ -93,26 +96,35 @@ local gdefines = {} --for FLT_MAX and others
|
|||||||
--------------------------------------------------------------------------
|
--------------------------------------------------------------------------
|
||||||
--helper functions
|
--helper functions
|
||||||
--------------------------------------------------------------------------
|
--------------------------------------------------------------------------
|
||||||
--iterates lines from a .h file and discards between #if.. and #endif
|
--minimal preprocessor
|
||||||
local function filelines(file)
|
local function filelines(file,locats)
|
||||||
local iflevels = {}
|
local iflevels = {}
|
||||||
|
--only one case is true
|
||||||
|
local function prepro_boolif(line)
|
||||||
|
local ma = line:match("#ifndef%s+IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT") or line:match("#ifndef%s+ImTextureID")
|
||||||
|
return not (ma==nil)
|
||||||
|
end
|
||||||
local function location_it()
|
local function location_it()
|
||||||
repeat
|
repeat
|
||||||
local line = file:read"*l"
|
local line = file:read"*l"
|
||||||
if not line then return nil end
|
if not line then return nil end
|
||||||
if line:sub(1,1) == "#" then
|
if line:sub(1,1) == "#" then
|
||||||
if line:match("#if") then
|
if line:match("#if") then
|
||||||
iflevels[#iflevels +1 ] = true
|
iflevels[#iflevels +1 ] = prepro_boolif(line)
|
||||||
elseif line:match("#endif") then
|
elseif line:match("#endif") then
|
||||||
iflevels[#iflevels] = nil
|
iflevels[#iflevels] = nil
|
||||||
|
elseif line:match("#elseif") then
|
||||||
|
iflevels[#iflevels] = false -- all false now
|
||||||
|
elseif line:match("#else") then
|
||||||
|
iflevels[#iflevels] = not iflevels[#iflevels]
|
||||||
end
|
end
|
||||||
-- skip
|
-- skip
|
||||||
elseif #iflevels == 0 then
|
elseif #iflevels == 0 or iflevels[#iflevels] then
|
||||||
-- drop IMGUI_APIX
|
-- drop IMGUI_APIX
|
||||||
line = line:gsub("IMGUI_IMPL_API","")
|
line = line:gsub("IMGUI_IMPL_API","")
|
||||||
-- drop IMGUI_API
|
-- drop IMGUI_API
|
||||||
line = line:gsub("IMGUI_API","")
|
line = line:gsub("IMGUI_API","")
|
||||||
return line
|
return line,locats[1]
|
||||||
end
|
end
|
||||||
until false
|
until false
|
||||||
end
|
end
|
||||||
@@ -1326,34 +1338,17 @@ print("IMGUI_VERSION",imgui_version)
|
|||||||
if HAVE_COMPILER then
|
if HAVE_COMPILER then
|
||||||
gdefines = get_defines{"IMGUI_VERSION","FLT_MAX"}
|
gdefines = get_defines{"IMGUI_VERSION","FLT_MAX"}
|
||||||
end
|
end
|
||||||
--first without gcc
|
|
||||||
---[[
|
|
||||||
print"------------------generation without precompiler------------------------"
|
|
||||||
local pipe,err = io.open("../imgui/imgui.h","r")
|
|
||||||
if not pipe then
|
|
||||||
error("could not open file:"..err)
|
|
||||||
end
|
|
||||||
|
|
||||||
local STP = struct_parser()
|
--generation
|
||||||
local FP = func_parser()
|
print("------------------generation with "..COMPILER.."------------------------")
|
||||||
|
|
||||||
for line in filelines(pipe) do
|
|
||||||
local line, comment = split_comment(line)
|
|
||||||
line = clean_spaces(line)
|
|
||||||
STP.insert(line,"")--comment)
|
|
||||||
FP.insert(line,"")--comment)
|
|
||||||
end
|
|
||||||
pipe:close()
|
|
||||||
FP:compute_overloads()
|
|
||||||
ADDnonUDT(FP)
|
|
||||||
cimgui_generation("_nopreprocess",STP,FP)
|
|
||||||
--]]
|
|
||||||
--then gcc
|
|
||||||
print"------------------generation with precompiler------------------------"
|
|
||||||
local pFP,pSTP,typedefs_dict2
|
local pFP,pSTP,typedefs_dict2
|
||||||
|
|
||||||
|
local pipe,err
|
||||||
if HAVE_COMPILER then
|
if HAVE_COMPILER then
|
||||||
local pipe,err = io.popen(CPRE..[[../imgui/imgui.h]],"r")
|
pipe,err = io.popen(CPRE..[[../imgui/imgui.h]],"r")
|
||||||
|
else
|
||||||
|
pipe,err = io.open([[../imgui/imgui.h]],"r")
|
||||||
|
end
|
||||||
|
|
||||||
if not pipe then
|
if not pipe then
|
||||||
error("could not execute gcc "..err)
|
error("could not execute gcc "..err)
|
||||||
@@ -1362,24 +1357,23 @@ end
|
|||||||
pSTP = struct_parser() --overwrite
|
pSTP = struct_parser() --overwrite
|
||||||
pFP = func_parser() --overwrite
|
pFP = func_parser() --overwrite
|
||||||
|
|
||||||
--local linesl = {}
|
local iterator = (HAVE_COMPILER and location) or filelines
|
||||||
for line in location(pipe,{"imgui"}) do
|
|
||||||
|
for line in iterator(pipe,{"imgui"}) do
|
||||||
local line, comment = split_comment(line)
|
local line, comment = split_comment(line)
|
||||||
--line = clean_spaces(line)
|
--line = clean_spaces(line)
|
||||||
--table.insert(linesl,line)
|
|
||||||
pSTP.insert(line,comment)
|
pSTP.insert(line,comment)
|
||||||
pFP.insert(line,comment)
|
pFP.insert(line,comment)
|
||||||
end
|
end
|
||||||
pipe:close()
|
pipe:close()
|
||||||
--save_data("./LINES.txt",table.concat(linesl,"\n"))
|
|
||||||
--save_data("./STPLINES.txt",table.concat(pSTP.lines,"\n"))
|
|
||||||
local ovstr = pFP:compute_overloads()
|
local ovstr = pFP:compute_overloads()
|
||||||
ADDnonUDT(pFP)
|
ADDnonUDT(pFP)
|
||||||
save_data("./output/overloads.txt",ovstr)
|
save_data("./output/overloads.txt",ovstr)
|
||||||
typedefs_dict2 = cimgui_generation("",pSTP,pFP)
|
typedefs_dict2 = cimgui_generation("",pSTP,pFP)
|
||||||
--check arg detection failure if no name in function declaration
|
--check arg detection failure if no name in function declaration
|
||||||
check_arg_detection(pFP.defsT,typedefs_dict2)
|
check_arg_detection(pFP.defsT,typedefs_dict2)
|
||||||
end
|
|
||||||
|
|
||||||
----------save fundefs in definitions.lua for using in bindings
|
----------save fundefs in definitions.lua for using in bindings
|
||||||
set_defines(pFP.defsT)
|
set_defines(pFP.defsT)
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user