mirror of
https://github.com/cimgui/cimgui.git
synced 2025-08-29 10:40:19 +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
|
elseif in_imgui then
|
||||||
--[[
|
--if in_function discard
|
||||||
-- 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 then
|
if in_function then
|
||||||
if line:match(function_closing_re) then
|
if line:match(function_closing_re) then
|
||||||
in_function = false
|
in_function = false
|
||||||
end
|
end
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
if line:match(function_re) and not line:match("typedef.*%b().*%b().*") then
|
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
|
if not line:match(function_closed_re) then
|
||||||
in_function = true
|
in_function = true
|
||||||
end
|
end
|
||||||
--end
|
|
||||||
elseif line:match("template") then
|
elseif line:match("template") then
|
||||||
--nothing
|
--nothing
|
||||||
elseif line:match("public") then
|
elseif line:match("public") then
|
||||||
@@ -92,23 +78,23 @@ local struct_op_close_re = "%b{}"
|
|||||||
local structnames = {}
|
local structnames = {}
|
||||||
local innerstructs = {}
|
local innerstructs = {}
|
||||||
-- Output the file
|
-- Output the file
|
||||||
|
print("/////////////// BEGIN AUTOGENERATED SEGMENT")
|
||||||
print("#ifndef IMGUI_STRUCTS_INCLUDED")
|
print("#ifndef IMGUI_STRUCTS_INCLUDED")
|
||||||
print("#define IMGUI_STRUCTS_INCLUDED")
|
print("#define IMGUI_STRUCTS_INCLUDED")
|
||||||
print("/////////////// BEGIN AUTOGENERATED SEGMENT")
|
|
||||||
for i,line in ipairs(cdefs) do
|
for i,line in ipairs(cdefs) do
|
||||||
repeat -- simulating continue with break
|
repeat -- simulating continue with break
|
||||||
|
|
||||||
if line:match(namespace_re) then
|
if line:match(namespace_re) then
|
||||||
in_namespace = true
|
in_namespace = true
|
||||||
end
|
end
|
||||||
structnames[#structnames + 1] = line:match(struct_re)
|
local structbegin = line:match(struct_re)
|
||||||
|
if structbegin then
|
||||||
if in_namespace then
|
structnames[#structnames + 1] = structbegin
|
||||||
if line:match(function_closing_re) then
|
if #structnames < 2 and structbegin~= "ImVector" then --not inner and not ImVector
|
||||||
--io.write( line,"\n")
|
io.write(line,"\n")
|
||||||
in_namespace = false
|
break
|
||||||
end
|
end
|
||||||
break -- dont write anything inside
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if structnames[#structnames] == "ImVector" then
|
if structnames[#structnames] == "ImVector" then
|
||||||
@@ -125,9 +111,21 @@ typedef struct ImVector ImVector;]]
|
|||||||
break -- dont write
|
break -- dont write
|
||||||
end
|
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 < 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
|
break
|
||||||
|
elseif not line:match("^{$") and not line:match(struct_closing_re) then --avoid tab { and };
|
||||||
|
line = " "..line
|
||||||
|
end
|
||||||
end
|
end
|
||||||
io.write( line,"\n")
|
io.write( line,"\n")
|
||||||
local struct_closed_name = line:match(struct_closed_re)
|
local struct_closed_name = line:match(struct_closed_re)
|
||||||
@@ -136,11 +134,13 @@ typedef struct ImVector ImVector;]]
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--if structnames[#structnames] then
|
|
||||||
if #structnames > 0 then
|
if #structnames > 0 then
|
||||||
if #structnames > 1 then --inner
|
if #structnames > 1 then --inner structs
|
||||||
innerstructs[structnames[#structnames]] = innerstructs[structnames[#structnames]] or {}
|
innerstructs[structnames[#structnames]] = innerstructs[structnames[#structnames]] or {}
|
||||||
local st = innerstructs[structnames[#structnames]]
|
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
|
st[#st + 1] = line
|
||||||
if line:match(struct_closing_re) and not line:match(struct_op_close_re) then
|
if line:match(struct_closing_re) and not line:match(struct_op_close_re) then
|
||||||
local structname = structnames[#structnames]
|
local structname = structnames[#structnames]
|
||||||
@@ -162,6 +162,6 @@ typedef struct ImVector ImVector;]]
|
|||||||
print(line)
|
print(line)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
print("//////////////// END AUTOGENERATED SEGMENT ")
|
|
||||||
print("#endif //IMGUI_STRUCTS_INCLUDED")
|
print("#endif //IMGUI_STRUCTS_INCLUDED")
|
||||||
|
print("//////////////// END AUTOGENERATED SEGMENT ")
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
|
/////////////// BEGIN AUTOGENERATED SEGMENT
|
||||||
#ifndef IMGUI_STRUCTS_INCLUDED
|
#ifndef IMGUI_STRUCTS_INCLUDED
|
||||||
#define IMGUI_STRUCTS_INCLUDED
|
#define IMGUI_STRUCTS_INCLUDED
|
||||||
/////////////// BEGIN AUTOGENERATED SEGMENT
|
|
||||||
struct ImDrawChannel;
|
struct ImDrawChannel;
|
||||||
typedef struct ImDrawChannel ImDrawChannel;
|
typedef struct ImDrawChannel ImDrawChannel;
|
||||||
struct ImDrawCmd;
|
struct ImDrawCmd;
|
||||||
@@ -743,5 +743,5 @@ union { int val_i; float val_f; void* val_p; };
|
|||||||
};
|
};
|
||||||
typedef struct Pair Pair;
|
typedef struct Pair Pair;
|
||||||
|
|
||||||
//////////////// END AUTOGENERATED SEGMENT
|
|
||||||
#endif //IMGUI_STRUCTS_INCLUDED
|
#endif //IMGUI_STRUCTS_INCLUDED
|
||||||
|
//////////////// END AUTOGENERATED SEGMENT
|
||||||
|
Reference in New Issue
Block a user