mirror of
https://github.com/cimgui/cimgui.git
synced 2025-10-09 11:21:38 +01:00
generator using tabs in structs
This commit is contained in:
@@ -40,33 +40,19 @@ repeat -- simulate continue with break
|
||||
|
||||
|
||||
elseif in_imgui then
|
||||
--[[
|
||||
-- Windows likes to add __stdcall__ to everything, but it isn't needed and is actually harmful when using under linux.
|
||||
-- However, it is needed for callbacks in windows.
|
||||
--if line:find("typedef") >= 0 and line.find(" PFNGL") < 0:
|
||||
if line:find("typedef") and not line:find(" PFNGL") then
|
||||
--line = line:gsub("__attribute__%(%(__stdcall__%)%) ", 'WINDOWS_STDCALL ')
|
||||
line = line:gsub('GL_APIENTRY ' , 'WINDOWS_STDCALL ')
|
||||
else
|
||||
--line = line:gsub("__attribute__%(%(__stdcall__%)%) ", '')
|
||||
line = line:gsub('GL_APIENTRY ', '')
|
||||
end
|
||||
-- While linux likes to add __attribute__((visibility("default")))
|
||||
line = line:gsub('__attribute__%(%(visibility%("default"%)%)%) ', '')
|
||||
line = line:gsub("__attribute__%(%(__stdcall__%)%) ", '')
|
||||
--]]
|
||||
--if in_function discard
|
||||
if in_function then
|
||||
if line:match(function_closing_re) then
|
||||
in_function = false
|
||||
end
|
||||
break
|
||||
end
|
||||
|
||||
if line:match(function_re) and not line:match("typedef.*%b().*%b().*") then
|
||||
--if not line:match("typedef.*%b().*%b().*") then --functypedef
|
||||
-- function and functypedef
|
||||
if not line:match(function_closed_re) then
|
||||
in_function = true
|
||||
end
|
||||
--end
|
||||
elseif line:match("template") then
|
||||
--nothing
|
||||
elseif line:match("public") then
|
||||
@@ -92,23 +78,23 @@ local struct_op_close_re = "%b{}"
|
||||
local structnames = {}
|
||||
local innerstructs = {}
|
||||
-- Output the file
|
||||
print("/////////////// BEGIN AUTOGENERATED SEGMENT")
|
||||
print("#ifndef IMGUI_STRUCTS_INCLUDED")
|
||||
print("#define IMGUI_STRUCTS_INCLUDED")
|
||||
print("/////////////// BEGIN AUTOGENERATED SEGMENT")
|
||||
|
||||
for i,line in ipairs(cdefs) do
|
||||
repeat -- simulating continue with break
|
||||
|
||||
if line:match(namespace_re) then
|
||||
in_namespace = true
|
||||
end
|
||||
structnames[#structnames + 1] = line:match(struct_re)
|
||||
|
||||
if in_namespace then
|
||||
if line:match(function_closing_re) then
|
||||
--io.write( line,"\n")
|
||||
in_namespace = false
|
||||
local structbegin = line:match(struct_re)
|
||||
if structbegin then
|
||||
structnames[#structnames + 1] = structbegin
|
||||
if #structnames < 2 and structbegin~= "ImVector" then --not inner and not ImVector
|
||||
io.write(line,"\n")
|
||||
break
|
||||
end
|
||||
break -- dont write anything inside
|
||||
end
|
||||
|
||||
if structnames[#structnames] == "ImVector" then
|
||||
@@ -125,9 +111,21 @@ typedef struct ImVector ImVector;]]
|
||||
break -- dont write
|
||||
end
|
||||
|
||||
if in_namespace then
|
||||
if line:match(function_closing_re) then
|
||||
--io.write( line,"\n")
|
||||
in_namespace = false
|
||||
end
|
||||
break -- dont write anything inside
|
||||
end
|
||||
|
||||
if #structnames < 2 then -- not inner
|
||||
if (#structnames > 0) and line:match("typedef") then --dont allow inner typedefs
|
||||
if (#structnames > 0) then
|
||||
if line:match("typedef") then --dont allow inner typedefs
|
||||
break
|
||||
elseif not line:match("^{$") and not line:match(struct_closing_re) then --avoid tab { and };
|
||||
line = " "..line
|
||||
end
|
||||
end
|
||||
io.write( line,"\n")
|
||||
local struct_closed_name = line:match(struct_closed_re)
|
||||
@@ -136,11 +134,13 @@ typedef struct ImVector ImVector;]]
|
||||
end
|
||||
end
|
||||
|
||||
--if structnames[#structnames] then
|
||||
if #structnames > 0 then
|
||||
if #structnames > 1 then --inner
|
||||
if #structnames > 1 then --inner structs
|
||||
innerstructs[structnames[#structnames]] = innerstructs[structnames[#structnames]] or {}
|
||||
local st = innerstructs[structnames[#structnames]]
|
||||
if not line:match("struct") and not line:match("^{$") and not line:match(struct_closing_re) then --avoid tab in struct { and };
|
||||
line = " "..line
|
||||
end
|
||||
st[#st + 1] = line
|
||||
if line:match(struct_closing_re) and not line:match(struct_op_close_re) then
|
||||
local structname = structnames[#structnames]
|
||||
@@ -162,6 +162,6 @@ typedef struct ImVector ImVector;]]
|
||||
print(line)
|
||||
end
|
||||
end
|
||||
|
||||
print("//////////////// END AUTOGENERATED SEGMENT ")
|
||||
print("#endif //IMGUI_STRUCTS_INCLUDED")
|
||||
print("//////////////// END AUTOGENERATED SEGMENT ")
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/////////////// BEGIN AUTOGENERATED SEGMENT
|
||||
#ifndef IMGUI_STRUCTS_INCLUDED
|
||||
#define IMGUI_STRUCTS_INCLUDED
|
||||
/////////////// BEGIN AUTOGENERATED SEGMENT
|
||||
struct ImDrawChannel;
|
||||
typedef struct ImDrawChannel ImDrawChannel;
|
||||
struct ImDrawCmd;
|
||||
@@ -743,5 +743,5 @@ union { int val_i; float val_f; void* val_p; };
|
||||
};
|
||||
typedef struct Pair Pair;
|
||||
|
||||
//////////////// END AUTOGENERATED SEGMENT
|
||||
#endif //IMGUI_STRUCTS_INCLUDED
|
||||
//////////////// END AUTOGENERATED SEGMENT
|
||||
|
Reference in New Issue
Block a user