mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-05-26 00:19:12 +12:00
[Qt] Initial Imgui integration
This commit is contained in:
parent
8ff2d7f9b2
commit
918645479a
211 changed files with 49460 additions and 21918 deletions
third_party/imgui-lua-bindings
144
third_party/imgui-lua-bindings/README.md
vendored
Normal file
144
third_party/imgui-lua-bindings/README.md
vendored
Normal file
|
@ -0,0 +1,144 @@
|
|||
# These are imgui bindings for lua.
|
||||
|
||||
ImGui https://github.com/ocornut/imgui
|
||||
|
||||
These bindings support a lot of common imgui operations except for initializing imgui.
|
||||
|
||||
This repo only deals with binding ImGui with lua and doesn't deal with setting up the ImGui impl files required to run ImGui, check out the ImGui repo for help with that.
|
||||
|
||||
For LOVE bindings check out https://github.com/slages/love-imgui (uses these C++ bindings and does the rest of the work for you).
|
||||
|
||||
Function support for dear imgui 1.60:
|
||||
|
||||
Normal Imgui functions: Supported: 204 Unsupported: 117
|
||||
Imgui DrawList functions: Supported: 36 Unsupported: 12
|
||||
|
||||
|
||||
## How to call these imgui bindings from lua
|
||||
|
||||
It mostly is the same as calling from C++ except for dealing with pointers and ImVecs
|
||||
|
||||
Function definition in C++
|
||||
```c++
|
||||
IMGUI_API bool RadioButton(const char* label, bool active);
|
||||
```
|
||||
How to call function in lua
|
||||
|
||||
```lua
|
||||
ret = imgui.RadioButton("String goes here", isActive)
|
||||
```
|
||||
|
||||
## Pointers:
|
||||
|
||||
Lua doesn't have pointers but it has multiple return values
|
||||
so instead of giving it a pointer, you give it a value and it will pass
|
||||
back the new value.
|
||||
|
||||
Function definition in C++
|
||||
```c++
|
||||
IMGUI_API void ShowTestWindow(bool* opened = NULL);
|
||||
```
|
||||
How to call function in lua
|
||||
```lua
|
||||
opened = imgui.ShowTestWindow(opened)
|
||||
```
|
||||
This can make some functions a bit weird. For example Begin.
|
||||
|
||||
Function definition in C++
|
||||
```c++
|
||||
IMGUI_API bool Begin(const char* name, bool* p_opened = NULL, ImGuiWindowFlags flags = 0);
|
||||
```
|
||||
|
||||
How to call function in lua (Note: optional arguments still work)
|
||||
```lua
|
||||
shoulddraw, p_opened = imgui.Begin("Name", p_opened)
|
||||
```
|
||||
|
||||
|
||||
Begin normally returns whether it's desirable to draw or not as well as setting the value
|
||||
of p_opened to whether the window is open or not. Still use the first return value to decide to whether to call the ImGui functions for that window and imgui.End().
|
||||
|
||||
|
||||
## ImVecs:
|
||||
|
||||
Those are arguments are expanded to separate variables instead of one object.
|
||||
|
||||
Function definition in C++
|
||||
```c+++
|
||||
IMGUI_API void SetNextWindowPos(const ImVec2& pos, ImGuiSetCond cond = 0);
|
||||
```
|
||||
|
||||
How to call function in lua
|
||||
```lua
|
||||
imgui.SetNextWindowPos(100, 50)
|
||||
```
|
||||
|
||||
## DrawList functions:
|
||||
|
||||
All functions that operate on drawlists are called with the prefix DrawList
|
||||
|
||||
Function definition in C++
|
||||
```c++
|
||||
IMGUI_API void AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness = 1.0f);
|
||||
```
|
||||
|
||||
How to call function in lua
|
||||
```lua
|
||||
imgui.DrawList_AddLine(
|
||||
imgui.DrawList_AddLine(minX, minY, maxX, maxY, 0xFF0000FF, 2)
|
||||
```
|
||||
Note you must specifiy the color in hex for now
|
||||
0x(ALPHA)(BLUE)(GREEN)(RED)
|
||||
0xFF0000FF = full opacity red
|
||||
|
||||
|
||||
## Enums:
|
||||
|
||||
Enums are exposed through a "constant" table. They're namespaced with "ImGui" stripped from the name.
|
||||
|
||||
```c++
|
||||
ImGui::SetNextWindowSize(ImVec2(550,680), ImGuiSetCond_FirstUseEver);
|
||||
ImGui::Begin("Demo", p_open, ImGuiWindowFlags_ShowBorders);
|
||||
ImGui::End()
|
||||
```
|
||||
|
||||
```lua
|
||||
imgui.SetNextWindowSize(550,680, imgui.constant.SetCond.FirstUseEver)
|
||||
imgui.Begin("Demo", true, imgui.constant.WindowFlags.ShowBorders)
|
||||
imgui.End()
|
||||
```
|
||||
|
||||
## How to build:
|
||||
|
||||
Generate iterator file (or use the one for 1.50 already in the repo)
|
||||
```
|
||||
./generate_imgui_bindings.pl <../imgui/imgui.h >imgui_iterator.inl
|
||||
```
|
||||
|
||||
This creates a file with info about imgui functions from the imgui.h file.
|
||||
|
||||
Then copy the macro definitions in imgui_lua_bindings.cpp and include imgui_iterator.inl in that the cpp file. This will generate static int impl_FunctionName(lua_State*L) {} functions for each imgui function. Bind these to lua functions and you're good to go. (Check out imgui_lua_bindings.cpp for a full example)
|
||||
|
||||
The imgui_lua_bindings.cpp has two functions RunString and LoadImguiBindings
|
||||
|
||||
To use the functions there first assign the global lState to a valid lua_State, then call LoadImguiBindings then run as many strings as you want.
|
||||
|
||||
## What is ENABLE_IM_LUA_END_STACK?
|
||||
|
||||
I made something to keep track of the imgui begin stack so that I could continue using
|
||||
imGui functions if an error ocurred in the lua script. If you don't care about that
|
||||
don't define ENABLE_IM_LUA_END_STACK. I'm using a std::deque of ints to store what the last
|
||||
begin calls were and then if the script errors I unwrap them with ends so that imgui won't
|
||||
complain when I render.
|
||||
|
||||
## License?
|
||||
I don't feel like writing a license so here's it in laymans terms...
|
||||
|
||||
You can use this code for whatever just don't redistribute the exact same source code and try to sell it, or claim that the source code was made by you.
|
||||
You can compile this source code and sell it. You can change this source code and sell the modified version.
|
||||
You can include this source code in whatever open source project (let me know please!). You can include it in whatever closed source project.
|
||||
|
||||
Just be chill and if you make a billion dollars send me an email or something.
|
||||
|
||||
## Contributing
|
||||
If you have any improvements create a pull request! If you want a function supported or disagree with how the bindings work make an issue!
|
487
third_party/imgui-lua-bindings/generate_imgui_bindings.pl
vendored
Normal file
487
third_party/imgui-lua-bindings/generate_imgui_bindings.pl
vendored
Normal file
|
@ -0,0 +1,487 @@
|
|||
#!/usr/bin/perl
|
||||
use strict;
|
||||
use warnings;
|
||||
use diagnostics;
|
||||
|
||||
# This works for IMGUI 1.60 and does not get all functions
|
||||
#
|
||||
# to use ./generate_imgui_bindings.pl <../imgui/imgui.h >imgui_iterator.inl
|
||||
# and define macros properly as in example imgui_lua_bindings.cpp
|
||||
#
|
||||
# check imgui_iterator for explanations of why some functions are not supported yet
|
||||
|
||||
require "./parse_blocks.pl";
|
||||
|
||||
sub generateNamespaceImgui {
|
||||
my ($imguiCodeBlock) = @_;
|
||||
|
||||
my $lineCaptureRegex = qr" *(IMGUI_API) *((const char\*)|([^ ]+)) *([^\(]+)\(([^\;]*)\);";
|
||||
my $doEndStackOptions = 1;
|
||||
my $terminator = "} \/\/ namespace ImGui";
|
||||
my $callPrefix = "";
|
||||
my $functionSuffix = "";
|
||||
|
||||
#define bannedNames with keys of functions to exclude them
|
||||
# EXAMPLE:
|
||||
my %bannedNames = (
|
||||
"NewFrame" => "banned",
|
||||
"Render" => "banned",
|
||||
"Shutdown" => "banned" );
|
||||
#
|
||||
# This is only useful for ENABLE_IM_LUA_END_STACK
|
||||
# We hold a list of differnet 'things' that can be pushed to the stack
|
||||
# i.e. Group for BeginGroup
|
||||
# It usually works like this BeginBlah EndBlah
|
||||
|
||||
# We have to redefine stuff when it doesn't work so cleanly
|
||||
my %beginN = (
|
||||
"TreeNode" => "Tree",
|
||||
"TreePush" => "Tree",
|
||||
"PushStyleVar" => "StyleVar"
|
||||
);
|
||||
my %changeN = (
|
||||
"Tree" => "TreePop",
|
||||
"StyleVar"=> "PopStyleVar"
|
||||
);
|
||||
my %endN = (
|
||||
"TreePop" => "Tree",
|
||||
"PopStyleVar" => "StyleVar"
|
||||
);
|
||||
my %endOverride = (
|
||||
"PopupModal" => "Popup",
|
||||
"PopupContextItem" => "Popup",
|
||||
"PopupContextWindow" => "Popup",
|
||||
"PopupContextVoid" => "Popup" );
|
||||
|
||||
generateImguiGeneric(
|
||||
$lineCaptureRegex,
|
||||
$doEndStackOptions,
|
||||
$terminator,
|
||||
$callPrefix,
|
||||
$functionSuffix,
|
||||
\%bannedNames,
|
||||
\%beginN,
|
||||
\%changeN,
|
||||
\%endN,
|
||||
\%endOverride,
|
||||
$imguiCodeBlock)
|
||||
}
|
||||
|
||||
sub generateDrawListFunctions {
|
||||
my ($imguiCodeBlock) = @_;
|
||||
|
||||
my $lineCaptureRegex = qr" *(IMGUI_API|inline) *((const char\*)|([^ ]+)) *([^\(]+)\(([^\;]*)\);";
|
||||
my $doEndStackOptions = 0;
|
||||
my $terminator = 0;
|
||||
my $callPrefix = "DRAW_LIST_";
|
||||
my $functionSuffix = "_DRAW_LIST";
|
||||
|
||||
#define bannedNames with keys of functions to exclude them
|
||||
# EXAMPLE:
|
||||
my %bannedNames = (
|
||||
);
|
||||
#
|
||||
# This is only useful for ENABLE_IM_LUA_END_STACK
|
||||
# We hold a list of differnet 'things' that can be pushed to the stack
|
||||
# i.e. Group for BeginGroup
|
||||
# It usually works like this BeginBlah EndBlah
|
||||
|
||||
# We have to redefine stuff when it doesn't work so cleanly
|
||||
my %beginN = (
|
||||
);
|
||||
my %changeN = (
|
||||
);
|
||||
my %endN = (
|
||||
);
|
||||
my %endOverride = (
|
||||
);
|
||||
|
||||
|
||||
generateImguiGeneric(
|
||||
$lineCaptureRegex,
|
||||
$doEndStackOptions,
|
||||
$terminator,
|
||||
$callPrefix,
|
||||
$functionSuffix,
|
||||
\%bannedNames,
|
||||
\%beginN,
|
||||
\%changeN,
|
||||
\%endN,
|
||||
\%endOverride,
|
||||
$imguiCodeBlock)
|
||||
}
|
||||
|
||||
sub generateImguiGeneric {
|
||||
my $lineCaptureRegex = shift;
|
||||
my $doEndStackOptions = shift;
|
||||
my $terminator = shift;
|
||||
my $callPrefix = shift;
|
||||
my $functionSuffix = shift;
|
||||
|
||||
#define bannedNames with keys of functions to exclude them
|
||||
# EXAMPLE:
|
||||
my $bannedNamesRef = shift;
|
||||
my %bannedNames = %{$bannedNamesRef};
|
||||
#
|
||||
# This is only useful for ENABLE_IM_LUA_END_STACK
|
||||
# We hold a list of differnet 'things' that can be pushed to the stack
|
||||
# i.e. Group for BeginGroup
|
||||
# It usually works like this BeginBlah EndBlah
|
||||
|
||||
# We have to redefine stuff when it doesn't work so cleanly
|
||||
my $beginNRef = shift;
|
||||
my %beginN = %{$beginNRef};
|
||||
my $changeNRef = shift;
|
||||
my %changeN = %{$changeNRef};
|
||||
my $endNRef = shift;
|
||||
my %endN = %{$endNRef};
|
||||
my $endOverrideRef = shift;
|
||||
my %endOverride = %{$endOverrideRef};
|
||||
|
||||
my ($imguiCodeBlock) = @_;
|
||||
|
||||
|
||||
my $numSupported = 0;
|
||||
my $numUnsupported = 0;
|
||||
my $line;
|
||||
my %funcNames;
|
||||
my %endTypeToInt;
|
||||
my @endTypes;
|
||||
my @functionsAlreadyAdded;
|
||||
foreach $line (split /\n/, $imguiCodeBlock) {
|
||||
#replace ImVec2(x, y) with ImVec2 x, y so it's easier for regex (and ImVec4)
|
||||
$line =~ s/ImVec2\(([^,]*),([^\)]*)\)/ImVec2 $1 $2/g;
|
||||
$line =~ s/ImVec4\(([^,]*),([^\)]*),([^\)]*),([^\)]*)\)/ImVec4 $1 $2 $3 $4/g;
|
||||
|
||||
#delete this so it's eaiser for regexes
|
||||
$line =~ s/ IM_PRINTFARGS\(.\);/;/g;
|
||||
if ($line =~ m/$lineCaptureRegex/) {
|
||||
print "//" . $line . "\n";
|
||||
# this will be set to 0 if something is not supported yet
|
||||
my $shouldPrint = 1;
|
||||
my @args = split(',', $6);
|
||||
# things to do before calling real c++ function
|
||||
my @before;
|
||||
# arguments to real c++ function
|
||||
my @funcArgs;
|
||||
# things to do after callign real c++ function
|
||||
my @after;
|
||||
# real c++ function name
|
||||
my $funcName = $5;
|
||||
|
||||
#say STDERR "Parsing function: " . $funcName;
|
||||
if (grep(/^$funcName$/, @functionsAlreadyAdded)) {
|
||||
#say STDERR $funcName;
|
||||
}
|
||||
push @functionsAlreadyAdded, $funcName;
|
||||
|
||||
if (defined($bannedNames{$funcName})) {
|
||||
print "//Not allowed to use this function\n";
|
||||
$shouldPrint = 0;
|
||||
}
|
||||
# c++ type of return value
|
||||
my $retType = $2;
|
||||
# macro used for calling function
|
||||
my $callMacro;
|
||||
# if it has a return value (yes I know this is not the cleanest code)
|
||||
my $hasRet = 1;
|
||||
if ($retType =~ /^void$/) {
|
||||
$callMacro = "${callPrefix}CALL_FUNCTION_NO_RET";
|
||||
$hasRet = 0;
|
||||
} elsif ($retType =~ /^const char\*$/) {
|
||||
$callMacro = "${callPrefix}CALL_FUNCTION";
|
||||
push(@funcArgs, "const char*");
|
||||
push(@after, "PUSH_STRING(ret)");
|
||||
} elsif ($retType =~ /^bool$/) {
|
||||
$callMacro = "${callPrefix}CALL_FUNCTION";
|
||||
push(@funcArgs, "bool");
|
||||
push(@after, "PUSH_BOOL(ret)");
|
||||
} elsif ($retType =~ /^float$/) {
|
||||
$callMacro = "${callPrefix}CALL_FUNCTION";
|
||||
push(@funcArgs, "float");
|
||||
push(@after, "PUSH_NUMBER(ret)");
|
||||
} elsif ($retType =~ /^ImVec2$/) {
|
||||
$callMacro = "${callPrefix}CALL_FUNCTION";
|
||||
push(@funcArgs, "ImVec2");
|
||||
push(@after, "PUSH_NUMBER(ret.x)");
|
||||
push(@after, "PUSH_NUMBER(ret.y)");
|
||||
} elsif ($retType =~ /^(unsigned int|ImGuiID|ImU32)$/) {
|
||||
$callMacro = "${callPrefix}CALL_FUNCTION";
|
||||
push(@funcArgs, "unsigned int");
|
||||
push(@after, "PUSH_NUMBER(ret)");
|
||||
} else {
|
||||
print "// Unsupported return type $retType\n";
|
||||
$shouldPrint = 0;
|
||||
}
|
||||
for (my $i = 0; $i < @args; $i++) {
|
||||
# bool * x = NULL or bool * x
|
||||
if ($args[$i] =~ m/^ *bool *\* *([^ =\[]*)( = NULL|) *$/) {
|
||||
my $name = $1;
|
||||
if ($2 =~ m/^ = NULL$/) {
|
||||
push(@before, "OPTIONAL_BOOL_POINTER_ARG($name)");
|
||||
} else {
|
||||
push(@before, "BOOL_POINTER_ARG($name)");
|
||||
}
|
||||
push(@funcArgs, $name);
|
||||
push(@after, "END_BOOL_POINTER($name)");
|
||||
# float * x
|
||||
} elsif ($args[$i] =~ m/^ *float *\* *([^ =\[]*)$/) {
|
||||
my $name = $1;
|
||||
push(@before, "FLOAT_POINTER_ARG($name)");
|
||||
push(@funcArgs, $name);
|
||||
push(@after, "END_FLOAT_POINTER($name)");
|
||||
# const float *, int count
|
||||
} elsif ($args[$i] =~ m/^ *const float *\* *([^ =\[]*)$/ && $args[$i + 1] =~ m/^ *int *([^ =\[]*)_count$/) {
|
||||
my $name = $1;
|
||||
push(@before, "FLOAT_ARRAY_ARG($name)");
|
||||
push(@funcArgs, $name);
|
||||
push(@funcArgs, "${name}_count");
|
||||
push(@after, "END_FLOAT_ARRAY($name)");
|
||||
$i++;
|
||||
# float a or float a = number
|
||||
} elsif ($args[$i] =~ m/^ *float *([^ =\[]*)( *= *[^ ]*|)$/) {
|
||||
my $name = $1;
|
||||
if ($2 =~ m/^ *= *([^ ]*)$/) {
|
||||
push(@before, "OPTIONAL_NUMBER_ARG($name, $1)");
|
||||
} else {
|
||||
push(@before, "NUMBER_ARG($name)");
|
||||
}
|
||||
push(@funcArgs, $name);
|
||||
# const char* a or const char* a = NULL or "blah"
|
||||
} elsif ($args[$i] =~ m/^ *const char\* *([^ =\[]*)( *= *(NULL|".*")|) *$/) {
|
||||
my $name = $1;
|
||||
if ($2 =~ m/^ *= *([^ ]*)$/) {
|
||||
push(@before, "OPTIONAL_LABEL_ARG($name, $1)");
|
||||
} else {
|
||||
push(@before, "LABEL_ARG($name)");
|
||||
}
|
||||
push(@funcArgs, $name);
|
||||
#const ImVec2& with default or not
|
||||
} elsif ($args[$i] =~ m/^ *(const)? ImVec2&? +([^ ]*) *(= * ImVec2 [^ ]* +[^ ]*|) *$/) {
|
||||
my $name = $2;
|
||||
if ($3 =~ m/^= * ImVec2 ([^ ]*) +([^ ]*)$/) {
|
||||
push(@before, "OPTIONAL_IM_VEC_2_ARG($name, $1, $2)");
|
||||
} else {
|
||||
push(@before, "IM_VEC_2_ARG($name)");
|
||||
}
|
||||
push(@funcArgs, $name);
|
||||
# ImVec2
|
||||
} elsif ($args[$i] =~ m/^ *ImVec2 ([^ ]*) *$/) {
|
||||
my $name = $1;
|
||||
push(@before, "IM_VEC_2_ARG($name)");
|
||||
push(@funcArgs, $name);
|
||||
#const ImVec4& with default or not
|
||||
} elsif ($args[$i] =~ m/^ *const ImVec4& +([^ ]*) *(= * ImVec4 [^ ]* +[^ ]* +[^ ]* +[^ ]*|) *$/) {
|
||||
my $name = $1;
|
||||
if ($2 =~ m/^= * ImVec4 +([^ ]*) +([^ ]*) +([^ ]*) +([^ ]*)$/) {
|
||||
push(@before, "OPTIONAL_IM_VEC_4_ARG($name, $1, $2, $3, $4)");
|
||||
} else {
|
||||
push(@before, "IM_VEC_4_ARG($name)");
|
||||
}
|
||||
push(@funcArgs, $name);
|
||||
# one of the various enums
|
||||
# we are handling these as ints
|
||||
} elsif ($args[$i] =~ m/^ *(ImGuiMouseButton|ImGuiTableBgTarget|ImGuiPopupFlags|ImGuiDataType|ImGuiDir|ImGuiCond|ImGuiFocusedFlags|ImGuiHoveredFlags|ImGuiWindowFlags|ImGuiCol|ImGuiStyleVar|ImGuiAlign|ImGuiColorEditMode|ImGuiMouseCursor|ImGuiSetCond|ImGuiInputTextFlags|ImGuiSelectableFlags|ImGuiSliderFlags|ImDrawFlags|ImGuiButtonFlags|ImGuiColorEditFlags|ImGuiComboFlags|ImGuiDockNodeFlags|ImGuiDragDropFlags|ImGuiPopupFlags|ImGuiTabBarFlags|ImGuiTabItemFlags|ImGuiTableColumnFlags|ImGuiTableFlags|ImGuiTableRowFlags|ImGuiTreeNodeFlags) ([^ =]*)( *= *[0-9]*|) *$/) {
|
||||
#These are ints
|
||||
my $name = $2;
|
||||
if ($3 =~ m/^ *= *([0-9]+)$/) {
|
||||
push(@before, "OPTIONAL_INT_ARG($name, $1)");
|
||||
} else {
|
||||
push(@before, "INT_ARG($name)");
|
||||
}
|
||||
push(@funcArgs, $name);
|
||||
#int with default value or not
|
||||
} elsif ($args[$i] =~ m/^ *int ([^ =\[]*)( = [^ ]*|) *$/) {
|
||||
my $name = $1;
|
||||
if ($2 =~ m/^ = ([^ ]*)$/) {
|
||||
push(@before, "OPTIONAL_INT_ARG($name, $1)");
|
||||
} else {
|
||||
push(@before, "INT_ARG($name)");
|
||||
}
|
||||
push(@funcArgs, $name);
|
||||
#unsigned int with default value or not
|
||||
} elsif ($args[$i] =~ m/^ *(unsigned +int|ImGuiID|ImU32) ([^ =\[]*)( = [^ ]*|) *$/) {
|
||||
my $name = $2;
|
||||
if ($3 =~ m/^ = ([^ ]*)$/) {
|
||||
push(@before, "OPTIONAL_UINT_ARG($name, $1)");
|
||||
} else {
|
||||
push(@before, "UINT_ARG($name)");
|
||||
}
|
||||
push(@funcArgs, $name);
|
||||
#ImTextureID or const ImTextureID&
|
||||
# const ImTextureID& is the same thing as var
|
||||
# as lua is concerned
|
||||
} elsif ($args[$i] =~ m/^ *(ImTextureID|const ImTextureID&) ([^ =\[]*) *$/) {
|
||||
my $name = $2;
|
||||
push(@before, "IM_TEXTURE_ID_ARG($name)");
|
||||
push(@funcArgs, $name);
|
||||
# bool with default value or not
|
||||
} elsif ($args[$i] =~ m/^ *bool ([^ =\[]*)( *= *true| *= *false|) *$/) {
|
||||
my $name = $1;
|
||||
if ($2 =~ m/^ *= *([^ ]*)$/) {
|
||||
push(@before, "OPTIONAL_BOOL_ARG($name, $1)");
|
||||
} else {
|
||||
push(@before, "BOOL_ARG($name)");
|
||||
}
|
||||
push(@funcArgs, $name);
|
||||
# int * x
|
||||
} elsif ($args[$i] =~ m/^ *int *\* *([^ =\[]*)$/) {
|
||||
my $name = $1;
|
||||
push(@before, "INT_POINTER_ARG($name)");
|
||||
push(@funcArgs, $name);
|
||||
push(@after, "END_INT_POINTER($name)");
|
||||
# unsigned int * x
|
||||
} elsif ($args[$i] =~ m/^ *unsigned +int *\* *([^ =\[]*)$/) {
|
||||
my $name = $1;
|
||||
push(@before, "UINT_POINTER_ARG($name)");
|
||||
push(@funcArgs, $name);
|
||||
push(@after, "END_UINT_POINTER($name)");
|
||||
# we don't support variadic functions yet but we let you use it without extra variables
|
||||
} elsif ($args[$i] =~ m/^ *\.\.\. *$/) {
|
||||
print "// Variadic functions aren't suppported but here it is anyway\n";
|
||||
} else {
|
||||
print "// Unsupported arg type " . $args[$i] . "\n";
|
||||
$shouldPrint = 0;
|
||||
}
|
||||
}
|
||||
if ($shouldPrint != 0) {
|
||||
my $luaFunc = $funcName;
|
||||
# Stupid way of implementing overriding
|
||||
while($funcNames{$luaFunc}) {
|
||||
$luaFunc .= "_" . scalar(@args);
|
||||
}
|
||||
$funcNames{$luaFunc} = 1;
|
||||
|
||||
|
||||
print "IMGUI_FUNCTION${functionSuffix}($luaFunc)\n";
|
||||
for (my $i = 0; $i < @before; $i++) {
|
||||
print $before[$i] . "\n";
|
||||
}
|
||||
|
||||
print $callMacro . "($funcName";
|
||||
for (my $i = 0; $i < @funcArgs; $i++) {
|
||||
print ", " . $funcArgs[$i];
|
||||
}
|
||||
print ")\n";
|
||||
|
||||
#for begin and end stack stuff
|
||||
if ($funcName =~ m/^Begin(.*)$/ || defined($beginN{$funcName})) {
|
||||
my $curEndType;
|
||||
if (defined($beginN{$funcName})) {
|
||||
$curEndType = $beginN{$funcName};
|
||||
} else {
|
||||
$curEndType = $1;
|
||||
}
|
||||
if (defined($endOverride{$curEndType})) {
|
||||
$curEndType = $endOverride{$curEndType};
|
||||
}
|
||||
if (!defined($endTypeToInt{$curEndType})) {
|
||||
$endTypeToInt{$curEndType} = scalar(@endTypes);
|
||||
push(@endTypes, $curEndType);
|
||||
}
|
||||
my $curEndTypeInt = $endTypeToInt{$curEndType};
|
||||
if ($hasRet) {
|
||||
print "IF_RET_ADD_END_STACK($curEndTypeInt)\n";
|
||||
} else {
|
||||
print "ADD_END_STACK($curEndTypeInt)\n";
|
||||
}
|
||||
} elsif ($funcName =~ m/^End(.*)$/ || defined($endN{$funcName})) {
|
||||
my $curEndType;
|
||||
if (defined($endN{$funcName})) {
|
||||
$curEndType = $endN{$funcName};
|
||||
} else {
|
||||
$curEndType = $1;
|
||||
}
|
||||
if (defined($endOverride{$curEndType})) {
|
||||
$curEndType = $endOverride{$curEndType};
|
||||
}
|
||||
if (!defined($endTypeToInt{$curEndType})) {
|
||||
$endTypeToInt{$curEndType} = scalar(@endTypes);
|
||||
push(@endTypes, $curEndType);
|
||||
}
|
||||
my $curEndTypeInt = $endTypeToInt{$curEndType};
|
||||
print "POP_END_STACK($curEndTypeInt)\n"
|
||||
}
|
||||
|
||||
for (my $i = 0; $i < @after; $i++) {
|
||||
print $after[$i] . "\n";
|
||||
}
|
||||
print "END_IMGUI_FUNC\n";
|
||||
$numSupported += 1;
|
||||
} else {
|
||||
$numUnsupported += 1;
|
||||
}
|
||||
} elsif ($terminator) {
|
||||
if ($line =~ m/^${terminator}$/) {
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
#for end stack stuff
|
||||
if ($doEndStackOptions)
|
||||
{
|
||||
print "END_STACK_START\n";
|
||||
for (my $i = 0; $i < @endTypes; $i++) {
|
||||
my $endFunc;
|
||||
if (defined($changeN{$endTypes[$i]})) {
|
||||
$endFunc = $changeN{$endTypes[$i]};
|
||||
} else {
|
||||
$endFunc = "End" . $endTypes[$i];
|
||||
}
|
||||
print "END_STACK_OPTION($i, " . $endFunc .")\n";
|
||||
}
|
||||
print "END_STACK_END\n";
|
||||
}
|
||||
|
||||
#debug info
|
||||
print STDERR "Supported: $numSupported Unsupported: $numUnsupported\n";
|
||||
|
||||
}
|
||||
|
||||
sub generateEnums {
|
||||
my $enumName = shift;
|
||||
my ($imguiCodeBlock) = @_;
|
||||
|
||||
my $lineCaptureRegex = qr"^ *(ImGui)([^, _]+)_([a-zA-Z0-9]+)\b";
|
||||
|
||||
print "START_ENUM($enumName)\n";
|
||||
my $line;
|
||||
foreach $line (split /\n/, $imguiCodeBlock) {
|
||||
if ($line =~ m/$lineCaptureRegex/) {
|
||||
die "Malformed enum at $enumName" unless ($2 eq $enumName);
|
||||
|
||||
print "//" . $line . "\n";
|
||||
print "MAKE_ENUM($1$2_$3,$3)\n";
|
||||
}
|
||||
}
|
||||
print "END_ENUM($enumName)\n";
|
||||
}
|
||||
|
||||
|
||||
my ($blocksref, $blocknamesref) = parse_blocks();
|
||||
|
||||
my @blocks = @$blocksref;
|
||||
my @blocknames = @$blocknamesref;
|
||||
|
||||
# @spaderthomas 3/1/2020: ImGui also puts its deprecated functions in namespace ImGui,
|
||||
# so we'll end up parsing a couple functions twice and causing compiler errors.
|
||||
#
|
||||
# This flag just means that we've parsed the main one, so don't parse the next one. If ImGui
|
||||
# splits up its header to multiple instances of namespace ImGui, this would break.
|
||||
my $alreadyParsedMainImguiNamespace = 0;
|
||||
|
||||
for (my $i=0; $i < scalar @blocks; $i++) {
|
||||
print "//" . $blocknames[$i] . "\n";
|
||||
if (($blocknames[$i] eq "namespace ImGui\n") and not $alreadyParsedMainImguiNamespace) {
|
||||
$alreadyParsedMainImguiNamespace = 1;
|
||||
generateNamespaceImgui($blocks[$i]);
|
||||
}
|
||||
if ($blocknames[$i] =~ m/enum ImGui(.*)_\n/) {
|
||||
generateEnums($1, $blocks[$i]);
|
||||
}
|
||||
if ($blocknames[$i] eq "struct ImDrawList\n") {
|
||||
generateDrawListFunctions($blocks[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
3856
third_party/imgui-lua-bindings/imgui_iterator.inl
vendored
Normal file
3856
third_party/imgui-lua-bindings/imgui_iterator.inl
vendored
Normal file
File diff suppressed because it is too large
Load diff
472
third_party/imgui-lua-bindings/imgui_lua_bindings.cpp
vendored
Normal file
472
third_party/imgui-lua-bindings/imgui_lua_bindings.cpp
vendored
Normal file
|
@ -0,0 +1,472 @@
|
|||
#include <stdio.h>
|
||||
#include <imgui.h>
|
||||
#include <deque>
|
||||
|
||||
#include "lua.hpp"
|
||||
|
||||
#define ENABLE_IM_LUA_END_STACK
|
||||
|
||||
#ifdef ENABLE_IM_LUA_END_STACK
|
||||
// Stack for imgui begin and end
|
||||
std::deque<int> endStack;
|
||||
static void AddToStack(int type) {
|
||||
endStack.push_back(type);
|
||||
}
|
||||
|
||||
static void PopEndStack(int type) {
|
||||
if (!endStack.empty()) {
|
||||
endStack.pop_back(); // hopefully the type matches
|
||||
}
|
||||
}
|
||||
|
||||
static void ImEndStack(int type);
|
||||
|
||||
#endif
|
||||
|
||||
#define IMGUI_FUNCTION_DRAW_LIST(name) \
|
||||
static int impl_draw_list_##name(lua_State *L) { \
|
||||
int max_args = lua_gettop(L); \
|
||||
int arg = 1; \
|
||||
int stackval = 0;
|
||||
|
||||
#define IMGUI_FUNCTION(name) \
|
||||
static int impl_##name(lua_State *L) { \
|
||||
int max_args = lua_gettop(L); \
|
||||
int arg = 1; \
|
||||
int stackval = 0;
|
||||
|
||||
// I use OpenGL so this is a GLuint
|
||||
// Using unsigned int cause im lazy don't copy me
|
||||
#define IM_TEXTURE_ID_ARG(name) \
|
||||
const ImTextureID name = (ImTextureID)luaL_checkinteger(L, arg++);
|
||||
|
||||
#define OPTIONAL_LABEL_ARG(name, otherwise) \
|
||||
const char* name; \
|
||||
if (arg <= max_args) { \
|
||||
name = lua_tostring(L, arg++); \
|
||||
} else { \
|
||||
name = otherwise; \
|
||||
}
|
||||
|
||||
#define LABEL_ARG(name) \
|
||||
size_t i_##name##_size; \
|
||||
const char * name = luaL_checklstring(L, arg++, &(i_##name##_size));
|
||||
|
||||
#define IM_VEC_2_ARG(name)\
|
||||
const lua_Number i_##name##_x = luaL_checknumber(L, arg++); \
|
||||
const lua_Number i_##name##_y = luaL_checknumber(L, arg++); \
|
||||
const ImVec2 name((double)i_##name##_x, (double)i_##name##_y);
|
||||
|
||||
#define OPTIONAL_IM_VEC_2_ARG(name, x, y) \
|
||||
lua_Number i_##name##_x = x; \
|
||||
lua_Number i_##name##_y = y; \
|
||||
if (arg <= max_args - 1) { \
|
||||
i_##name##_x = luaL_checknumber(L, arg++); \
|
||||
i_##name##_y = luaL_checknumber(L, arg++); \
|
||||
} \
|
||||
const ImVec2 name((double)i_##name##_x, (double)i_##name##_y);
|
||||
|
||||
#define IM_VEC_4_ARG(name) \
|
||||
const lua_Number i_##name##_x = luaL_checknumber(L, arg++); \
|
||||
const lua_Number i_##name##_y = luaL_checknumber(L, arg++); \
|
||||
const lua_Number i_##name##_z = luaL_checknumber(L, arg++); \
|
||||
const lua_Number i_##name##_w = luaL_checknumber(L, arg++); \
|
||||
const ImVec4 name((double)i_##name##_x, (double)i_##name##_y, (double)i_##name##_z, (double)i_##name##_w);
|
||||
|
||||
#define OPTIONAL_IM_VEC_4_ARG(name, x, y, z, w) \
|
||||
lua_Number i_##name##_x = x; \
|
||||
lua_Number i_##name##_y = y; \
|
||||
lua_Number i_##name##_z = z; \
|
||||
lua_Number i_##name##_w = w; \
|
||||
if (arg <= max_args - 1) { \
|
||||
i_##name##_x = luaL_checknumber(L, arg++); \
|
||||
i_##name##_y = luaL_checknumber(L, arg++); \
|
||||
i_##name##_z = luaL_checknumber(L, arg++); \
|
||||
i_##name##_w = luaL_checknumber(L, arg++); \
|
||||
} \
|
||||
const ImVec4 name((double)i_##name##_x, (double)i_##name##_y, (double)i_##name##_z, (double)i_##name##_w);
|
||||
|
||||
#define NUMBER_ARG(name)\
|
||||
lua_Number name = luaL_checknumber(L, arg++);
|
||||
|
||||
#define OPTIONAL_NUMBER_ARG(name, otherwise)\
|
||||
lua_Number name = otherwise; \
|
||||
if (arg <= max_args) { \
|
||||
name = lua_tonumber(L, arg++); \
|
||||
}
|
||||
|
||||
#define FLOAT_POINTER_ARG(name) \
|
||||
float i_##name##_value = luaL_checknumber(L, arg++); \
|
||||
float* name = &(i_##name##_value);
|
||||
|
||||
#define END_FLOAT_POINTER(name) \
|
||||
if (name != NULL) { \
|
||||
lua_pushnumber(L, i_##name##_value); \
|
||||
stackval++; \
|
||||
}
|
||||
|
||||
#define FLOAT_ARRAY_ARG(name) \
|
||||
if (!lua_istable(L, arg)) { \
|
||||
return luaL_error(L, "Expected table for argument %d", arg); \
|
||||
} \
|
||||
int name##_count = lua_objlen(L, arg); \
|
||||
float* name = new float[name##_count]; \
|
||||
for (int i = 0; i < name##_count; i++) { \
|
||||
lua_rawgeti(L, arg, i + 1); \
|
||||
name[i] = luaL_checknumber(L, -1); \
|
||||
lua_pop(L, 1); \
|
||||
} \
|
||||
arg++;
|
||||
|
||||
#define END_FLOAT_ARRAY(name) \
|
||||
delete[] name;
|
||||
|
||||
#define OPTIONAL_INT_ARG(name, otherwise)\
|
||||
int name = otherwise; \
|
||||
if (arg <= max_args) { \
|
||||
name = (int)lua_tonumber(L, arg++); \
|
||||
}
|
||||
|
||||
#define INT_ARG(name) \
|
||||
const int name = (int)luaL_checknumber(L, arg++);
|
||||
|
||||
#define OPTIONAL_UINT_ARG(name, otherwise)\
|
||||
unsigned int name = otherwise; \
|
||||
if (arg <= max_args) { \
|
||||
name = (unsigned int)lua_tonumber(L, arg++); \
|
||||
}
|
||||
|
||||
#define UINT_ARG(name) \
|
||||
const unsigned int name = (unsigned int)luaL_checkinteger(L, arg++);
|
||||
|
||||
#define INT_POINTER_ARG(name) \
|
||||
int i_##name##_value = (int)luaL_checkinteger(L, arg++); \
|
||||
int* name = &(i_##name##_value);
|
||||
|
||||
#define END_INT_POINTER(name) \
|
||||
if (name != NULL) { \
|
||||
lua_pushnumber(L, i_##name##_value); \
|
||||
stackval++; \
|
||||
}
|
||||
|
||||
#define UINT_POINTER_ARG(name) \
|
||||
unsigned int i_##name##_value = (unsigned int)luaL_checkinteger(L, arg++); \
|
||||
unsigned int* name = &(i_##name##_value);
|
||||
|
||||
#define END_UINT_POINTER(name) \
|
||||
if (name != NULL) { \
|
||||
lua_pushnumber(L, i_##name##_value); \
|
||||
stackval++; \
|
||||
}
|
||||
|
||||
#define BOOL_POINTER_ARG(name) \
|
||||
bool i_##name##_value = lua_toboolean(L, arg++); \
|
||||
bool* name = &(i_##name##_value);
|
||||
|
||||
#define OPTIONAL_BOOL_POINTER_ARG(name) \
|
||||
bool i_##name##_value; \
|
||||
bool* name = NULL; \
|
||||
if (arg <= max_args) { \
|
||||
i_##name##_value = lua_toboolean(L, arg++); \
|
||||
name = &(i_##name##_value); \
|
||||
}
|
||||
|
||||
#define OPTIONAL_BOOL_ARG(name, otherwise) \
|
||||
bool name = otherwise; \
|
||||
if (arg <= max_args) { \
|
||||
name = lua_toboolean(L, arg++); \
|
||||
}
|
||||
|
||||
#define BOOL_ARG(name) \
|
||||
bool name = lua_toboolean(L, arg++);
|
||||
|
||||
#define CALL_FUNCTION(name, retType,...) \
|
||||
retType ret = ImGui::name(__VA_ARGS__);
|
||||
|
||||
#define DRAW_LIST_CALL_FUNCTION(name, retType,...) \
|
||||
retType ret = ImGui::GetWindowDrawList()->name(__VA_ARGS__);
|
||||
|
||||
#define CALL_FUNCTION_NO_RET(name, ...) \
|
||||
ImGui::name(__VA_ARGS__);
|
||||
|
||||
#define DRAW_LIST_CALL_FUNCTION_NO_RET(name, ...) \
|
||||
ImGui::GetWindowDrawList()->name(__VA_ARGS__);
|
||||
|
||||
#define PUSH_STRING(name) \
|
||||
lua_pushstring(L, name); \
|
||||
stackval++;
|
||||
|
||||
#define PUSH_NUMBER(name) \
|
||||
lua_pushnumber(L, name); \
|
||||
stackval++;
|
||||
|
||||
#define PUSH_BOOL(name) \
|
||||
lua_pushboolean(L, (int) name); \
|
||||
stackval++;
|
||||
|
||||
#define END_BOOL_POINTER(name) \
|
||||
if (name != NULL) { \
|
||||
lua_pushboolean(L, (int)i_##name##_value); \
|
||||
stackval++; \
|
||||
}
|
||||
|
||||
#define END_IMGUI_FUNC \
|
||||
return stackval; \
|
||||
}
|
||||
|
||||
#ifdef ENABLE_IM_LUA_END_STACK
|
||||
#define IF_RET_ADD_END_STACK(type) \
|
||||
if (ret) { \
|
||||
AddToStack(type); \
|
||||
}
|
||||
|
||||
#define ADD_END_STACK(type) \
|
||||
AddToStack(type);
|
||||
|
||||
#define POP_END_STACK(type) \
|
||||
PopEndStack(type);
|
||||
|
||||
#define END_STACK_START \
|
||||
static void ImEndStack(int type) { \
|
||||
switch(type) {
|
||||
|
||||
#define END_STACK_OPTION(type, function) \
|
||||
case type: \
|
||||
ImGui::function(); \
|
||||
break;
|
||||
|
||||
#define END_STACK_END \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define END_STACK_START
|
||||
#define END_STACK_OPTION(type, function)
|
||||
#define END_STACK_END
|
||||
#define IF_RET_ADD_END_STACK(type)
|
||||
#define ADD_END_STACK(type)
|
||||
#define POP_END_STACK(type)
|
||||
#endif
|
||||
|
||||
#define START_ENUM(name)
|
||||
#define MAKE_ENUM(c_name,lua_name)
|
||||
#define END_ENUM(name)
|
||||
|
||||
#include "imgui_iterator.inl"
|
||||
|
||||
|
||||
static const struct luaL_Reg imguilib[] = {
|
||||
#undef IMGUI_FUNCTION
|
||||
#define IMGUI_FUNCTION(name) {#name, impl_##name},
|
||||
#undef IMGUI_FUNCTION_DRAW_LIST
|
||||
#define IMGUI_FUNCTION_DRAW_LIST(name) {"DrawList_" #name, impl_draw_list_##name},
|
||||
// These defines are just redefining everything to nothing so
|
||||
// we can get the function names
|
||||
#undef IM_TEXTURE_ID_ARG
|
||||
#define IM_TEXTURE_ID_ARG(name)
|
||||
#undef OPTIONAL_LABEL_ARG
|
||||
#define OPTIONAL_LABEL_ARG(name, otherwise)
|
||||
#undef LABEL_ARG
|
||||
#define LABEL_ARG(name)
|
||||
#undef IM_VEC_2_ARG
|
||||
#define IM_VEC_2_ARG(name)
|
||||
#undef OPTIONAL_IM_VEC_2_ARG
|
||||
#define OPTIONAL_IM_VEC_2_ARG(name, x, y)
|
||||
#undef IM_VEC_4_ARG
|
||||
#define IM_VEC_4_ARG(name)
|
||||
#undef OPTIONAL_IM_VEC_4_ARG
|
||||
#define OPTIONAL_IM_VEC_4_ARG(name, x, y, z, w)
|
||||
#undef NUMBER_ARG
|
||||
#define NUMBER_ARG(name)
|
||||
#undef OPTIONAL_NUMBER_ARG
|
||||
#define OPTIONAL_NUMBER_ARG(name, otherwise)
|
||||
#undef FLOAT_POINTER_ARG
|
||||
#define FLOAT_POINTER_ARG(name)
|
||||
#undef END_FLOAT_POINTER
|
||||
#define END_FLOAT_POINTER(name)
|
||||
#undef FLOAT_ARRAY_ARG
|
||||
#define FLOAT_ARRAY_ARG(name)
|
||||
#undef END_FLOAT_ARRAY
|
||||
#define END_FLOAT_ARRAY(name)
|
||||
#undef OPTIONAL_INT_ARG
|
||||
#define OPTIONAL_INT_ARG(name, otherwise)
|
||||
#undef INT_ARG
|
||||
#define INT_ARG(name)
|
||||
#undef OPTIONAL_UINT_ARG
|
||||
#define OPTIONAL_UINT_ARG(name, otherwise)
|
||||
#undef UINT_ARG
|
||||
#define UINT_ARG(name)
|
||||
#undef INT_POINTER_ARG
|
||||
#define INT_POINTER_ARG(name)
|
||||
#undef END_INT_POINTER
|
||||
#define END_INT_POINTER(name)
|
||||
#undef UINT_POINTER_ARG
|
||||
#define UINT_POINTER_ARG(name)
|
||||
#undef END_UINT_POINTER
|
||||
#define END_UINT_POINTER(name)
|
||||
#undef BOOL_POINTER_ARG
|
||||
#define BOOL_POINTER_ARG(name)
|
||||
#undef OPTIONAL_BOOL_POINTER_ARG
|
||||
#define OPTIONAL_BOOL_POINTER_ARG(name)
|
||||
#undef OPTIONAL_BOOL_ARG
|
||||
#define OPTIONAL_BOOL_ARG(name, otherwise)
|
||||
#undef BOOL_ARG
|
||||
#define BOOL_ARG(name)
|
||||
#undef CALL_FUNCTION
|
||||
#define CALL_FUNCTION(name, retType, ...)
|
||||
#undef DRAW_LIST_CALL_FUNCTION
|
||||
#define DRAW_LIST_CALL_FUNCTION(name, retType, ...)
|
||||
#undef CALL_FUNCTION_NO_RET
|
||||
#define CALL_FUNCTION_NO_RET(name, ...)
|
||||
#undef DRAW_LIST_CALL_FUNCTION_NO_RET
|
||||
#define DRAW_LIST_CALL_FUNCTION_NO_RET(name, ...)
|
||||
#undef PUSH_STRING
|
||||
#define PUSH_STRING(name)
|
||||
#undef PUSH_NUMBER
|
||||
#define PUSH_NUMBER(name)
|
||||
#undef PUSH_BOOL
|
||||
#define PUSH_BOOL(name)
|
||||
#undef END_BOOL_POINTER
|
||||
#define END_BOOL_POINTER(name)
|
||||
#undef END_IMGUI_FUNC
|
||||
#define END_IMGUI_FUNC
|
||||
#undef END_STACK_START
|
||||
#define END_STACK_START
|
||||
#undef END_STACK_OPTION
|
||||
#define END_STACK_OPTION(type, function)
|
||||
#undef END_STACK_END
|
||||
#define END_STACK_END
|
||||
#undef IF_RET_ADD_END_STACK
|
||||
#define IF_RET_ADD_END_STACK(type)
|
||||
#undef ADD_END_STACK
|
||||
#define ADD_END_STACK(type)
|
||||
#undef POP_END_STACK
|
||||
#define POP_END_STACK(type)
|
||||
#undef START_ENUM
|
||||
#define START_ENUM(name)
|
||||
#undef MAKE_ENUM
|
||||
#define MAKE_ENUM(c_name,lua_name)
|
||||
#undef END_ENUM
|
||||
#define END_ENUM(name)
|
||||
|
||||
#include "imgui_iterator.inl"
|
||||
// {"Button", impl_Button},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
static void PushImguiEnums(lua_State* lState, const char* tableName) {
|
||||
lua_pushstring(lState, tableName);
|
||||
lua_newtable(lState);
|
||||
|
||||
#undef START_ENUM
|
||||
#undef MAKE_ENUM
|
||||
#undef END_ENUM
|
||||
#define START_ENUM(name) \
|
||||
lua_pushstring(lState, #name); \
|
||||
lua_newtable(lState); \
|
||||
{ \
|
||||
int i = 1;
|
||||
#define MAKE_ENUM(c_name,lua_name) \
|
||||
lua_pushstring(lState, #lua_name); \
|
||||
lua_pushnumber(lState, c_name); \
|
||||
lua_rawset(lState, -3);
|
||||
#define END_ENUM(name) \
|
||||
} \
|
||||
lua_rawset(lState, -3);
|
||||
// These defines are just redefining everything to nothing so
|
||||
// we get only the enums.
|
||||
#undef IMGUI_FUNCTION
|
||||
#define IMGUI_FUNCTION(name)
|
||||
#undef IMGUI_FUNCTION_DRAW_LIST
|
||||
#define IMGUI_FUNCTION_DRAW_LIST(name)
|
||||
#undef IM_TEXTURE_ID_ARG
|
||||
#define IM_TEXTURE_ID_ARG(name)
|
||||
#undef OPTIONAL_LABEL_ARG
|
||||
#define OPTIONAL_LABEL_ARG(name, otherwise)
|
||||
#undef LABEL_ARG
|
||||
#define LABEL_ARG(name)
|
||||
#undef IM_VEC_2_ARG
|
||||
#define IM_VEC_2_ARG(name)
|
||||
#undef OPTIONAL_IM_VEC_2_ARG
|
||||
#define OPTIONAL_IM_VEC_2_ARG(name, x, y)
|
||||
#undef IM_VEC_4_ARG
|
||||
#define IM_VEC_4_ARG(name)
|
||||
#undef OPTIONAL_IM_VEC_4_ARG
|
||||
#define OPTIONAL_IM_VEC_4_ARG(name, x, y, z, w)
|
||||
#undef NUMBER_ARG
|
||||
#define NUMBER_ARG(name)
|
||||
#undef OPTIONAL_NUMBER_ARG
|
||||
#define OPTIONAL_NUMBER_ARG(name, otherwise)
|
||||
#undef FLOAT_POINTER_ARG
|
||||
#define FLOAT_POINTER_ARG(name)
|
||||
#undef END_FLOAT_POINTER
|
||||
#define END_FLOAT_POINTER(name)
|
||||
#undef FLOAT_ARRAY_ARG
|
||||
#define FLOAT_ARRAY_ARG(name)
|
||||
#undef END_FLOAT_ARRAY
|
||||
#define END_FLOAT_ARRAY(name)
|
||||
#undef OPTIONAL_INT_ARG
|
||||
#define OPTIONAL_INT_ARG(name, otherwise)
|
||||
#undef INT_ARG
|
||||
#define INT_ARG(name)
|
||||
#undef OPTIONAL_UINT_ARG
|
||||
#define OPTIONAL_UINT_ARG(name, otherwise)
|
||||
#undef UINT_ARG
|
||||
#define UINT_ARG(name)
|
||||
#undef INT_POINTER_ARG
|
||||
#define INT_POINTER_ARG(name)
|
||||
#undef END_INT_POINTER
|
||||
#define END_INT_POINTER(name)
|
||||
#undef UINT_POINTER_ARG
|
||||
#define UINT_POINTER_ARG(name)
|
||||
#undef END_UINT_POINTER
|
||||
#define END_UINT_POINTER(name)
|
||||
#undef BOOL_POINTER_ARG
|
||||
#define BOOL_POINTER_ARG(name)
|
||||
#undef OPTIONAL_BOOL_POINTER_ARG
|
||||
#define OPTIONAL_BOOL_POINTER_ARG(name)
|
||||
#undef OPTIONAL_BOOL_ARG
|
||||
#define OPTIONAL_BOOL_ARG(name, otherwise)
|
||||
#undef BOOL_ARG
|
||||
#define BOOL_ARG(name)
|
||||
#undef CALL_FUNCTION
|
||||
#define CALL_FUNCTION(name, retType, ...)
|
||||
#undef DRAW_LIST_CALL_FUNCTION
|
||||
#define DRAW_LIST_CALL_FUNCTION(name, retType, ...)
|
||||
#undef CALL_FUNCTION_NO_RET
|
||||
#define CALL_FUNCTION_NO_RET(name, ...)
|
||||
#undef DRAW_LIST_CALL_FUNCTION_NO_RET
|
||||
#define DRAW_LIST_CALL_FUNCTION_NO_RET(name, ...)
|
||||
#undef PUSH_STRING
|
||||
#define PUSH_STRING(name)
|
||||
#undef PUSH_NUMBER
|
||||
#define PUSH_NUMBER(name)
|
||||
#undef PUSH_BOOL
|
||||
#define PUSH_BOOL(name)
|
||||
#undef END_BOOL_POINTER
|
||||
#define END_BOOL_POINTER(name)
|
||||
#undef END_IMGUI_FUNC
|
||||
#define END_IMGUI_FUNC
|
||||
#undef END_STACK_START
|
||||
#define END_STACK_START
|
||||
#undef END_STACK_OPTION
|
||||
#define END_STACK_OPTION(type, function)
|
||||
#undef END_STACK_END
|
||||
#define END_STACK_END
|
||||
#undef IF_RET_ADD_END_STACK
|
||||
#define IF_RET_ADD_END_STACK(type)
|
||||
#undef ADD_END_STACK
|
||||
#define ADD_END_STACK(type)
|
||||
#undef POP_END_STACK
|
||||
#define POP_END_STACK(type)
|
||||
|
||||
#include "imgui_iterator.inl"
|
||||
|
||||
lua_rawset(lState, -3);
|
||||
};
|
||||
|
||||
void LoadImguiBindings(lua_State* lState) {
|
||||
lua_newtable(lState);
|
||||
luaL_setfuncs(lState, imguilib, 0);
|
||||
PushImguiEnums(lState, "constant");
|
||||
lua_setglobal(lState, "imgui");
|
||||
}
|
85
third_party/imgui-lua-bindings/parse_blocks.pl
vendored
Normal file
85
third_party/imgui-lua-bindings/parse_blocks.pl
vendored
Normal file
|
@ -0,0 +1,85 @@
|
|||
##!/usr/bin/perl
|
||||
#use strict;
|
||||
#use warnings;
|
||||
#use diagnostics;
|
||||
#
|
||||
#my ($blocksref, $blocknamesref) = parse_blocks();
|
||||
#
|
||||
#my @blocks = @$blocksref;
|
||||
#my @blocknames = @$blocknamesref;
|
||||
#
|
||||
#my $name;
|
||||
#my $block;
|
||||
#foreach $name (@blocknames) {
|
||||
# print "BLOCKNAME" . $name;
|
||||
#}
|
||||
#
|
||||
#foreach $block (@blocks) {
|
||||
# print "---------------BLOCK START-----------\n";
|
||||
# print $block;
|
||||
# print "---------------BLOCK END -------------\n"
|
||||
#}
|
||||
|
||||
|
||||
|
||||
# WARNING THIS FUNCTION WILL MESS UP ALL OF PARSING IF IT SEES
|
||||
# A DIFFERENT NUMBER OF BLOCKNAMES AS BLOCKS...
|
||||
# TODO FIX THIS ^
|
||||
|
||||
#returns list of string blocks from stdin
|
||||
|
||||
|
||||
sub does_line_match_end_block {
|
||||
my $line = shift;
|
||||
|
||||
# Make sure you take into account random whitespace that could happen by using [ ]*[\t]*
|
||||
my $match = 0;
|
||||
$match |= $line =~ m/^};[ ]*[\t]*\/\//; # Semicolon, comment
|
||||
$match |= $line =~ m/^};[ ]*[\t]*$/; # Semicolon, no comment
|
||||
$match |= $line =~ m/^}[ ]*[\t]*\/\//; # No semicolon, comment
|
||||
$match |= $line =~ m/^}[ ]*[\t]*$/; # No semicolon, no comment
|
||||
return $match;
|
||||
}
|
||||
|
||||
sub does_line_match_begin_block {
|
||||
my $line = shift;
|
||||
|
||||
my $match = 0;
|
||||
$match |= $line =~ m/^{[ ]*[\t]*$/;
|
||||
return $match
|
||||
}
|
||||
|
||||
sub parse_blocks {
|
||||
my @blocks;
|
||||
my @blocknames;
|
||||
my $lastline;
|
||||
my $curBlock;
|
||||
while (my $line = <STDIN>) {
|
||||
if (does_line_match_begin_block($line)) {
|
||||
push @blocknames, $lastline;
|
||||
$curBlock = "";
|
||||
next;
|
||||
}
|
||||
|
||||
if (does_line_match_end_block($line)) {
|
||||
push @blocks, $curBlock;
|
||||
|
||||
# Enforce the invariant that we should have the same number of elements in blocks / block names
|
||||
if (scalar @blocks != scalar @blocknames) {
|
||||
print STDERR "The parser did a bad and has mismatched block open / close.";
|
||||
print STDERR "This is probably a problem with the regular expression that matches block open and close.";
|
||||
die
|
||||
}
|
||||
|
||||
$curBlock = "";
|
||||
|
||||
next;
|
||||
}
|
||||
|
||||
$curBlock .= $line . "\n";
|
||||
$lastline = $line;
|
||||
}
|
||||
return (\@blocks, \@blocknames);
|
||||
}
|
||||
|
||||
1;
|
Loading…
Add table
Add a link
Reference in a new issue