diff --git a/README.md b/README.md index aeade11..35bd2ff 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,9 @@ 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 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. (this repo was done with gcc) * 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, cl or nocompiler. Run it with gcc, clang or cl and LuaJIT on your PATH. +* edit `generator/generator.bat` on windows, or `generator/generator.sh` on linux, to choose between gcc, clang, cl or nocompiler and to choose desired implementations. +* edit config_generator.lua for adding includes needed by your chosen implementations. +* Run generator.bat or generator.sh 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. # generate binding diff --git a/generator/config_generator.lua b/generator/config_generator.lua new file mode 100644 index 0000000..1a15d59 --- /dev/null +++ b/generator/config_generator.lua @@ -0,0 +1,3 @@ +return { + vulkan = {[[C:\VulkanSDK\1.1.130.0\Include]]} +} \ No newline at end of file diff --git a/generator/generator.lua b/generator/generator.lua index 6d60af0..bee6598 100644 --- a/generator/generator.lua +++ b/generator/generator.lua @@ -189,6 +189,13 @@ end --------------------------------functions for C generation +--load parser module +local cpp2ffi = require"cpp2ffi" +local read_data = cpp2ffi.read_data +local save_data = cpp2ffi.save_data +local copyfile = cpp2ffi.copyfile +local serializeTableF = cpp2ffi.serializeTableF + local function func_header_impl_generate(FP) local outtab = {} @@ -197,11 +204,19 @@ local function func_header_impl_generate(FP) if t.cimguiname then local cimf = FP.defsT[t.cimguiname] local def = cimf[t.signature] - if def.ret then --not constructor - local addcoment = def.comment or "" + local addcoment = def.comment or "" + if def.constructor then + -- it happens with vulkan impl but constructor ImGui_ImplVulkanH_Window is not needed + --assert(def.stname ~= "","constructor without struct") + --table.insert(outtab,"CIMGUI_API "..def.stname.."* "..def.ov_cimguiname ..(empty and "(void)" or --def.args)..";"..addcoment.."\n") + elseif def.destructor then + --table.insert(outtab,"CIMGUI_API void "..def.ov_cimguiname..def.args..";"..addcoment.."\n") + else + if def.stname == "" then --ImGui namespace or top level table.insert(outtab,"CIMGUI_API".." "..def.ret.." "..def.ov_cimguiname..def.args..";"..addcoment.."\n") else + cpp2ffi.prtable(def) error("class function in implementations") end end @@ -424,12 +439,7 @@ local function DefsByStruct(FP) end ---load parser module -local cpp2ffi = require"cpp2ffi" -local read_data = cpp2ffi.read_data -local save_data = cpp2ffi.save_data -local copyfile = cpp2ffi.copyfile -local serializeTableF = cpp2ffi.serializeTableF + ----------custom ImVector templates local function generate_templates(code,templates) @@ -710,14 +720,22 @@ local parser2 if #implementations > 0 then parser2 = cpp2ffi.Parser() - + + local config = require"config_generator" for i,impl in ipairs(implementations) do local source = [[../imgui/examples/imgui_impl_]].. impl .. ".h " local locati = [[imgui_impl_]].. impl local pipe,err + local extra_includes = "" + local include_cmd = COMPILER=="cl" and [[ /I ]] or [[ -I ]] + if config[impl] then + for j,inc in ipairs(config[impl]) do + extra_includes = extra_includes .. include_cmd .. inc .. " " + end + end if HAVE_COMPILER then - pipe,err = io.popen(CPRE..source,"r") + pipe,err = io.popen(CPRE..extra_includes..source,"r") else pipe,err = io.open(source,"r") end