From e25f9f6844adcb21b6eb2405fbf5f8bcf1ff648a Mon Sep 17 00:00:00 2001 From: sonoro1234 Date: Fri, 24 Mar 2023 17:23:28 +0100 Subject: [PATCH] add generator options "nochar" and "noimstrv" according to issue #186 --- generator/cpp2ffi.lua | 15 ++++++++++++++- generator/generator.bat | 4 ++-- generator/generator.lua | 9 +++++++++ generator/generator.sh | 4 ++-- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/generator/cpp2ffi.lua b/generator/cpp2ffi.lua index 936c6f0..ca46f05 100644 --- a/generator/cpp2ffi.lua +++ b/generator/cpp2ffi.lua @@ -986,15 +986,28 @@ local function ADDIMSTR_S(FP) if dd.signature == defT2.signature then doadd = false; print("skip _S addition",defT2.cimguiname) + --M.prtable(defT2) break end end + --delete imstrv generation + if FP.NOIMSTRV then + newcdefs[#newcdefs] = nil + cimf[t.signature] = nil + for i,v in ipairs(cimf) do + if v.signature == t.signature then + table.remove(cimf, i) + break + end + end + end --add _S version - if doadd then + if doadd and not FP.NOCHAR then cimf[#cimf+1] = defT2 cimf[defT2.signature] = defT2 newcdefs[#newcdefs+1] = {stname=t.stname,funcname=t.funcname,args=defT2.args,signature=defT2.signature,cimguiname=defT2.cimguiname,ret =defT2.ret} end + end else print("not cimguiname in");M.prtable(t) end diff --git a/generator/generator.bat b/generator/generator.bat index 00f06cb..c9b292c 100644 --- a/generator/generator.bat +++ b/generator/generator.bat @@ -15,10 +15,10 @@ set PATH=%PATH%;C:\anima;C:\mingws\i686-7.2.0-release-posix-dwarf-rt_v5-rev1\min :: set PATH=%PATH%;C:\luaGL\sources\luajit-master\luajit-master\bin\mingw32;C:\mingw32\bin; ::process files :: 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 +:: 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 :: 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) -luajit ./generator.lua gcc "internal" glfw opengl3 opengl2 sdl2 +luajit ./generator.lua gcc "internal noimstrv" glfw opengl3 opengl2 sdl2 ::leave console open cmd /k diff --git a/generator/generator.lua b/generator/generator.lua index 4af3489..9684ead 100644 --- a/generator/generator.lua +++ b/generator/generator.lua @@ -9,6 +9,8 @@ local COMPILER = script_args[1] 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 COMMENTS_GENERATION = script_args[2]:match("comments") 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 IMGUI_PATH = os.getenv"IMGUI_PATH" or "../imgui" local CFLAGS = "" local CPRE,CTEST @@ -249,7 +251,9 @@ local function cimgui_generation(parser) cstructsstr = cstructsstr.."\n#define IMGUI_HAS_DOCK 1\n" end if gdefines.IMGUI_HAS_IMSTR then + if not (NOCHAR or NOIMSTRV) then cstructsstr = cstructsstr.."\n#define IMGUI_HAS_IMSTR 1\n" + end end hstrfile = hstrfile:gsub([[#include "imgui_structs%.h"]],cstructsstr) @@ -291,7 +295,10 @@ if gdefines.IMGUI_HAS_DOCK then ]] end +assert(not NOCHAR or not NOIMSTRV,"nochar and noimstrv cant be set at the same time") print("IMGUI_HAS_IMSTR",gdefines.IMGUI_HAS_IMSTR) +print("NOCHAR",NOCHAR) +print("NOIMSTRV",NOIMSTRV) print("IMGUI_HAS_DOCK",gdefines.IMGUI_HAS_DOCK) print("IMGUI_VERSION",gdefines.IMGUI_VERSION) @@ -311,6 +318,8 @@ local function parseImGuiHeader(header,names) parser.UDTs = {"ImVec2","ImVec4","ImColor","ImRect"} --parser.gen_template_typedef = gen_template_typedef --use auto parser.COMMENTS_GENERATION = COMMENTS_GENERATION + parser.NOCHAR = NOCHAR + parser.NOIMSTRV = NOIMSTRV local defines = parser:take_lines(CPRE..header,names,COMPILER) return parser diff --git a/generator/generator.sh b/generator/generator.sh index e012c5d..92d7ae4 100755 --- a/generator/generator.sh +++ b/generator/generator.sh @@ -13,7 +13,7 @@ #process files # 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 +# 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 # 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) @@ -22,4 +22,4 @@ then suffix='.exe' fi -luajit$suffix ./generator.lua gcc "internal" glfw opengl3 opengl2 sdl2 +luajit$suffix ./generator.lua gcc "internal noimstrv" glfw opengl3 opengl2 sdl2