script param "constructors" to add the _Construct version of constructors issue #278

This commit is contained in:
sonoro1234
2024-09-18 14:36:22 +02:00
parent 0c7f67607d
commit 411924f104
5 changed files with 15 additions and 1 deletions

View File

@@ -37,7 +37,7 @@ Notes:
* 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
* you need to use also a C++ compiler for doing preprocessing: gcc (In windows MinGW-W64-builds for example), clang or cl (MSVC). (this repo was done with gcc) * you need to use also a C++ compiler for doing preprocessing: gcc (In windows MinGW-W64-builds for example), clang or cl (MSVC). (this repo was done with gcc)
* update `imgui` folder to the version you desire. * update `imgui` folder to the version you desire.
* edit `generator/generator.bat` on windows, or `generator/generator.sh` on linux, to choose between gcc, clang, or cl and to choose desired backends and whether imgui_internal is generated or not, Freetype2 is used or not and comments are generated or not * edit `generator/generator.bat` on windows, or `generator/generator.sh` on linux, to choose between gcc, clang, or cl and to choose desired backends and whether imgui_internal is generated or not, Freetype2 is used or not and comments are generated or not and if constructors are generated also with versions performing just initialization of structs provided by yourself (_Construct is added to the constructor names)
* the defaults of generator are gcc as compiler, imgui_internal included and sdl, glfw, vulkan, opengl2 and opengl3 as backends. * the defaults of generator are gcc as compiler, imgui_internal included and sdl, glfw, vulkan, opengl2 and opengl3 as backends.
* edit config_generator.lua for adding includes needed by your chosen backends (vulkan needs that). * edit config_generator.lua for adding includes needed by your chosen backends (vulkan needs that).
* Run generator.bat or generator.sh with gcc, clang or cl and LuaJIT on your PATH. * Run generator.bat or generator.sh with gcc, clang or cl and LuaJIT on your PATH.

View File

@@ -2421,6 +2421,12 @@ local function func_implementation(FP)
table.insert(outtab,"{\n") table.insert(outtab,"{\n")
table.insert(outtab," return IM_NEW("..def.stname..")"..def.call_args..";\n") table.insert(outtab," return IM_NEW("..def.stname..")"..def.call_args..";\n")
table.insert(outtab,"}\n") table.insert(outtab,"}\n")
if FP.CONSTRUCTORS_GENERATION then
table.insert(outtab,"CIMGUI_API void "..def.ov_cimguiname.."_Construct("..def.stname.."* self"..(empty and "" or ","..def.args:sub(2,-2))..")\n")
table.insert(outtab,"{\n")
table.insert(outtab," IM_PLACEMENT_NEW(self)"..def.stname..def.call_args..";\n")
table.insert(outtab,"}\n")
end
elseif def.destructor then elseif def.destructor then
local args = "("..def.stname.."* self)" local args = "("..def.stname.."* self)"
local fname = def.stname.."_destroy" local fname = def.stname.."_destroy"
@@ -2491,6 +2497,9 @@ local function func_header_generate_funcs(FP)
if def.constructor then if def.constructor then
assert(def.stname ~= "","constructor without struct") assert(def.stname ~= "","constructor without struct")
table.insert(outtab,"CIMGUI_API "..def.stname.."* "..def.ov_cimguiname ..(empty and "(void)" or def.args)..";"..addcoment.."\n") table.insert(outtab,"CIMGUI_API "..def.stname.."* "..def.ov_cimguiname ..(empty and "(void)" or def.args)..";"..addcoment.."\n")
if FP.CONSTRUCTORS_GENERATION then
table.insert(outtab,"CIMGUI_API void "..def.ov_cimguiname.."_Construct("..def.stname.."* self"..(empty and "" or ","..def.args:sub(2,-2))..")\n")
end
elseif def.destructor then elseif def.destructor then
table.insert(outtab,"CIMGUI_API void "..def.ov_cimguiname..def.args..";"..addcoment.."\n") table.insert(outtab,"CIMGUI_API void "..def.ov_cimguiname..def.args..";"..addcoment.."\n")
else --not constructor else --not constructor

View File

@@ -16,6 +16,7 @@ set PATH=%PATH%;C:\anima;C:\mingws\i686-7.2.0-release-posix-dwarf-rt_v5-rev1\min
::process files ::process files
:: arg[1] compiler name gcc, clang or cl :: arg[1] compiler name gcc, clang or cl
:: arg[2] options as words in one string: internal for imgui_internal generation, freetype for freetype generation, comments for comments generation, nochar to skip char* function version, noimstrv to skip imstrv :: arg[2] options as words in one string: internal for imgui_internal generation, freetype for freetype generation, comments for comments generation, nochar to skip char* function version, noimstrv to skip imstrv
:: "constructors" adds the _Construct version of constructors
:: examples: "" "internal" "internal freetype comments" :: examples: "" "internal" "internal freetype comments"
:: arg[3..n] name of implementations to generate and/or CFLAGS (e.g. -DIMGUI_USER_CONFIG or -DIMGUI_USE_WCHAR32) :: arg[3..n] name of implementations to generate and/or CFLAGS (e.g. -DIMGUI_USER_CONFIG or -DIMGUI_USE_WCHAR32)
luajit ./generator.lua gcc "internal noimstrv" glfw opengl3 opengl2 sdl2 %* luajit ./generator.lua gcc "internal noimstrv" glfw opengl3 opengl2 sdl2 %*

View File

@@ -9,6 +9,7 @@ local COMPILER = script_args[1]
local INTERNAL_GENERATION = script_args[2]:match("internal") and true or false local INTERNAL_GENERATION = script_args[2]:match("internal") and true or false
local FREETYPE_GENERATION = script_args[2]:match("freetype") and true or false local FREETYPE_GENERATION = script_args[2]:match("freetype") and true or false
local COMMENTS_GENERATION = script_args[2]:match("comments") and true or false local COMMENTS_GENERATION = script_args[2]:match("comments") and true or false
local CONSTRUCTORS_GENERATION = script_args[2]:match("constructors") and true or false
local NOCHAR = script_args[2]:match("nochar") and true or false local NOCHAR = script_args[2]:match("nochar") and true or false
local NOIMSTRV = script_args[2]:match("noimstrv") and true or false local NOIMSTRV = script_args[2]:match("noimstrv") and true or false
local IMGUI_PATH = os.getenv"IMGUI_PATH" or "../imgui" local IMGUI_PATH = os.getenv"IMGUI_PATH" or "../imgui"
@@ -67,6 +68,7 @@ print("HAVE_COMPILER",HAVE_COMPILER)
print("INTERNAL_GENERATION",INTERNAL_GENERATION) print("INTERNAL_GENERATION",INTERNAL_GENERATION)
print("FREETYPE_GENERATION",FREETYPE_GENERATION) print("FREETYPE_GENERATION",FREETYPE_GENERATION)
print("COMMENTS_GENERATION",COMMENTS_GENERATION) print("COMMENTS_GENERATION",COMMENTS_GENERATION)
print("CONSTRUCTORS_GENERATION",CONSTRUCTORS_GENERATION)
print("CPRE",CPRE) print("CPRE",CPRE)
-------------------------------------------------------------------------- --------------------------------------------------------------------------
--this table has the functions to be skipped in generation --this table has the functions to be skipped in generation
@@ -321,6 +323,7 @@ local function parseImGuiHeader(header,names)
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.NOCHAR = NOCHAR parser.NOCHAR = NOCHAR
parser.NOIMSTRV = NOIMSTRV parser.NOIMSTRV = NOIMSTRV
local defines = parser:take_lines(CPRE..header,names,COMPILER) local defines = parser:take_lines(CPRE..header,names,COMPILER)

View File

@@ -14,6 +14,7 @@
#process files #process files
# arg[1] compiler name gcc, clang, or cl # arg[1] compiler name gcc, clang, or cl
# arg[2] options as words in one string: internal for imgui_internal generation, freetype for freetype generation, comments for comments generation, nochar to skip char* function version, noimstrv to skip imstrv # arg[2] options as words in one string: internal for imgui_internal generation, freetype for freetype generation, comments for comments generation, nochar to skip char* function version, noimstrv to skip imstrv
# "constructors" adds the _Construct version of constructors
# examples: "" "internal" "internal freetype" "comments internal" # examples: "" "internal" "internal freetype" "comments internal"
# arg[3..n] name of implementations to generate and/or CLFLAGS (e.g. -DIMGUI_USER_CONFIG or -DIMGUI_USE_WCHAR32) # arg[3..n] name of implementations to generate and/or CLFLAGS (e.g. -DIMGUI_USER_CONFIG or -DIMGUI_USE_WCHAR32)
# #