sonoro1234 / luajit-imgui Goto Github PK
View Code? Open in Web Editor NEWLuaJIT ffi binding for imgui, backends and extension widgets
License: MIT License
LuaJIT ffi binding for imgui, backends and extension widgets
License: MIT License
Dont find many wrappers which compile and have examples it's nice thanks
When I use the following code I get too many callbacks
as an error after a while:
lib.igInputText("##input", "test", 1024, ig.lib.ImGuiInputTextFlags_CallbackCompletion, function()
print("Hi")
return 0
end, nil)
What is the proper way to pass callbacks to InputText
?
Sorry to write here, but it is not possible to contact you via github.
I am making a c++ application with imgui and a couple more add-ons. And I want to make a scripting for the application. So there will be some folder from which my application takes the scripts. So I want to ask how to do it. So far I have stopped at using sol bindings. I haven't really figured it out yet, but as far as I know, you have to manually specify what you can call from under lua, and it will be difficult to add all the methods manually. Is it possible to combine your work in any way?
If I use the following lines of code on Windows 10,
ImGui_ImplSDL2_InitForSDLRenderer(&window, &renderer);
ImGui_ImplSDL2_NewFrame();
igNewFrame();
I just get the error below. What gives?
Assertion failed!
Expression: g.IO.Fonts->IsBuild() && 'Font Atlas not built!
Make sure you called ImGui_ImplXXXX_NewFrame() function
for renderer backend, which shiuld call
io.Fonts->GetTexDataAsRGBA32() / GetTexDataAsAlpha8()`
Depending on the compiler used, there is a crash when the functions return a user defined type like ImVec2 and others.
To avoid that you should use use_nonUDT2 after require as in:
local ig = require"imgui.glfw"
ig.use_nonUDT2() --this is needed if compiled with MSVC
I have been able to test mingw-w64 which doesnt need this and MSVC that needs it.
I would like to have a report for other compilers and systems
The title says it all, i dont really have any experience in cmake and i find it difficult to build.
Can you please add a new release or create a new release every time a new imgui version rolls out?
Much appreciated.
Hi. I need to load several scripts into one Luajit interpreter. There is a problem: windows does not work.
I use ready-made binary files from release v0.2b anima LuaJIT-Window-0.2b-Win32.zip
When running the two scripts LuaJIT-Window\examples\minimal_main.lua error: Picture
When running one minimal_main all is fine: Picture
This doesn't work on SDL and on GLFW.
I also tried to implement a wrap that would create a window when it was absent and return it when it was present:
local ffi = require "ffi"
local sdl = require "sdl2_ffi"
ffi.cdef [[
typedef struct SDL_Window SDL_Window;
SDL_Window *SDL_GL_GetCurrentWindow(void);
void* SDL_GL_GetCurrentContext(void);
int SDL_GL_MakeCurrent(SDL_Window* window,void* context);
]]
local function createWindow()
local openWindow = sdl.SDL_GL_GetCurrentWindow()
if openWindow == nil then
if (sdl.init(sdl.INIT_VIDEO + sdl.INIT_TIMER) ~= 0) then
print(string.format("Error: %s\n", sdl.getError()));
return -1;
end
sdl.gL_SetAttribute(sdl.GL_CONTEXT_FLAGS, sdl.GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);
sdl.gL_SetAttribute(sdl.GL_CONTEXT_PROFILE_MASK, sdl.GL_CONTEXT_PROFILE_CORE);
sdl.gL_SetAttribute(sdl.GL_DOUBLEBUFFER, 1);
sdl.gL_SetAttribute(sdl.GL_DEPTH_SIZE, 24);
sdl.gL_SetAttribute(sdl.GL_STENCIL_SIZE, 8);
sdl.gL_SetAttribute(sdl.GL_CONTEXT_MAJOR_VERSION, 3);
sdl.gL_SetAttribute(sdl.GL_CONTEXT_MINOR_VERSION, 2);
local current = ffi.new("SDL_DisplayMode[1]")
sdl.getCurrentDisplayMode(0, current);
local window = sdl.createWindow("ImGui SDL2+OpenGL3 example", sdl.WINDOWPOS_CENTERED, sdl.WINDOWPOS_CENTERED, 700,
500,
sdl.WINDOW_OPENGL + sdl.WINDOW_RESIZABLE);
local gl_context = sdl.gL_CreateContext(window);
return window, gl_context
end
return openWindow, sdl.SDL_GL_GetCurrentContext()
end
return createWindow
With this approach, I can't get the context right. One window does start to draw imgui from different scripts, but every tick the picture blinks
I can afford to create one window, for multiple scripts, since I use Viewports, so it's even for the best.
Please advise how to fix the bug with windows hanging (like in the first option with minimal_main) or losing context through the wrapper.
I try to compile with MSYS2-Mingw64. On Windows 11
Branch is "docking-inter"
I don't need anima, I just want to make GLFW and ImGui work in Protoplug, which is a VST plugin scriptable with LUA.
I want to only compile the stuff necessary.
Started to cmake it with
/mingw64/bin/cmake -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_BUILD_TYPE=RelWithDebInfo -DIMPL_SDL=no -DGLFW_PATH="/C/dev/projects/builds/glfw-orig-build" -DLUAJIT_BIN="C:/dev/projects/builds/cimgui" .
Problem/Question 1: The readme.md is vague about where to point -DGLFW_PATH. Should it point to a cmake project? Should it point to a directory containing the glfw DLL? To the headers? A install Dir?
Then I go /mingw64/bin/mingw32-make.exe install
Result: I ran into various compilation issues causec by missing includes. This issues I think I was able to solve by adding more include directories to CMakeLists.txt and redo the cmake step. Seems the include dirs I have added where just missing. Don't know how the project ever compiled,to be honest...
Problem/Question 2: Finally I ran into a number of compile errors like the console capture below. I was not able to get rid of these.
It seems quite confusing because actually the missing classes like CanvasState are there, but somehow they don't get used.
How can I make the project compile?
[ 64%] Building CXX object CMakeFiles/cimgui_base.dir/cimnodes_r/cimnodes_r.cpp.obj
[ 68%] Building CXX object CMakeFiles/cimgui_base.dir/cimnodes_r/ImNodes/ImNodes.cpp.obj
C:\dev\projects\LuaJIT-ImGui\cimnodes_r\ImNodes\ImNodes.cpp:35:1: error: ‘CanvasState’ does not name a type
35 | CanvasState* gCanvas = nullptr;
| ^~~~~~~~~~~
C:\dev\projects\LuaJIT-ImGui\cimnodes_r\ImNodes\ImNodes.cpp:133:5: error: ‘CanvasState’ does not name a type; did you mean ‘_CanvasStateImpl’?
133 | CanvasState* PrevCanvas = nullptr;
| ^~~~~~~~~~~
| _CanvasStateImpl
C:\dev\projects\LuaJIT-ImGui\cimnodes_r\ImNodes\ImNodes.cpp:138:1: error: ‘CanvasState’ does not name a type
138 | CanvasState::CanvasState() noexcept
| ^~~~~~~~~~~
C:\dev\projects\LuaJIT-ImGui\cimnodes_r\ImNodes\ImNodes.cpp:154:1: error: ‘CanvasState’ does not name a type
154 | CanvasState::~CanvasState()
| ^~~~~~~~~~~
I am on Linux Mint 20, and libsdl2-dev
is installed with apt. I checked out both LuaJIT-ImGui
and LuaJIT-SDL2
.
The folder structure was:
SomeFolder
|- LuaJIT-ImGui
|- LuaJIT-SDL2
After looking at the example build scirpt in /build
, I was trying with
SomeFolder/LuaJIT-ImGui/build$ cmake -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DIMPL_SDL=yes -DIMPL_OPENGL2=yes -DIMPL_OPENGL3=yes -DIMPL_EXTRAS=yes -DSDL_PATH="../../LuaJIT-SDL2/" -DLUAJIT_BIN="/usr/local/share/luajit-imgui/" ..
The output was:
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- GLFW_PATHnotdefined
-- SDL_PATH defined as ../../LuaJIT-SDL2/
-- sdlfound
CMake Warning (dev) at CMakeLists.txt:134 (get_target_property):
Policy CMP0045 is not set: Error on non-existent target in
get_target_property. Run "cmake --help-policy CMP0045" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.
get_target_property() called with non-existent target "SDL2::SDL2".
This warning is for project developers. Use -Wno-dev to suppress it.
-- sdlinclude is SDL_INCLUDE-NOTFOUND
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
SDL_INCLUDE
used as include directory in directory SomeFolder/LuaJIT-ImGui
used as include directory in directory SomeFolder/LuaJIT-ImGui
used as include directory in directory SomeFolder/LuaJIT-ImGui
used as include directory in directory SomeFolder/LuaJIT-ImGui
used as include directory in directory SomeFolder/LuaJIT-ImGui
used as include directory in directory SomeFolder/LuaJIT-ImGui
used as include directory in directory SomeFolder/LuaJIT-ImGui
used as include directory in directory SomeFolder/LuaJIT-ImGui
used as include directory in directory SomeFolder/LuaJIT-ImGui
-- Configuring incomplete, errors occurred!
See also "SomeFolder/LuaJIT-ImGui/build/CMakeFiles/CMakeOutput.log".
Was I wrong pointing to a suitable SDL_PATH
? I am a bit confused seeing sdlfound
. Reading up the CMakeLists.txt
I guess there was problem getting SDL_INCLUDE
with SDL::SDL2
from the given SDL_PATH
, but I can't figure out which folder I need to point it to. Sorry if my question is a bit dumb, I am not very familiar with cmake tbh.
Good afternoon. I build for Windows x64. For some reason, my application freezes whenever Imgui_Impl_glfw_opengl3
is called. Could you please tell me if there is a way to fix this? Thank you very much
Will this project ever come to LuaRocks, the lua package manager?
Some functions with array argument is not callable through generic version due to its ffi ctype is invalid, for example,
function M.Combo(a1,a2,a3,a4,a5,a6) -- generic version
if (ffi.istype('const char* const[]',a3) or ffi.istype('const char const[]',a3) or ffi.istype('const char const[][]',a3)) then return M.Combo_Str_arr(a1,a2,a3,a4,a5) end
if (ffi.istype('const char*',a3) or type(a3)=='string') then return M.Combo_Str(a1,a2,a3,a4) end
if ffi.istype('bool(*)(void* data,int idx,const char** out_text)',a3) then return M.Combo_FnBoolPtr(a1,a2,a3,a4,a5,a6) end
print(a1,a2,a3,a4,a5,a6)
error'M.Combo could not find overloaded'
end
Creating any instance of array with unknown size from ffi will lead to error, for example,
t0=ffi.typeof('char []')
p=ffi.new('char[1]')
print(ffi.istype(t0,p)) -- output false
q=t0(). -- error
How about replace all [] with *?
Attempt to clone the repository using git clone https://github.com/sonoro1234/LuaJIT-ImGui.git --recursive
leads to such error.
Same thing when trying to pull submodules separately using git submodule update --init --recursive
.
$ git clone https://github.com/sonoro1234/LuaJIT-ImGui.git --recursive
Cloning into 'LuaJIT-ImGui'...
remote: Enumerating objects: 524, done.
remote: Total 524 (delta 0), reused 0 (delta 0), pack-reused 524
Receiving objects: 100% (524/524), 225.69 KiB | 373.00 KiB/s, done.
Resolving deltas: 100% (330/330), done.
Submodule 'cimgui' (https://github.com/sonoro1234/cimgui.git) registered for path 'cimgui'
Cloning into 'D:/Dev/GitHub/mda/LuaJIT-ImGui/cimgui'...
remote: Enumerating objects: 48, done.
remote: Counting objects: 100% (48/48), done.
remote: Compressing objects: 100% (31/31), done.
remote: Total 1416 (delta 21), reused 37 (delta 16), pack-reused 1368
Receiving objects: 100% (1416/1416), 1.72 MiB | 2.92 MiB/s, done.
Resolving deltas: 100% (970/970), done.
error: Server does not allow request for unadvertised object 67f3b097a5090dd074be959fb9c794bd75096a1c
Fetched in submodule path 'cimgui', but it did not contain 67f3b097a5090dd074be959fb9c794bd75096a1c. Direct fetching of that commit failed.
Great job with the project!
Which license are you using to release this library? I'm listing it on Awesome dear imgui but it would be helpful to know the license as well. Thanks!
Generic version is still experimental
Its purpose is to detect the overloaded version from arguments
Here are some failing cases
from implot
M.PushPlotStyleVarFloat = lib.igPushPlotStyleVarFloat
M.PushPlotStyleVarInt = lib.igPushPlotStyleVarInt
function M.PushPlotStyleVar(a1,a2) -- generic version
if (ffi.istype('float',a2) or type(a2)=='number') then return M.PushPlotStyleVarFloat(a1,a2) end
if (ffi.istype('int',a2) or type(a2)=='number') then return M.PushPlotStyleVarInt(a1,a2) end
print(a1,a2)
error'M.PushPlotStyleVar could not find overloaded'
end
It is imposible to discriminate float from int when it is a Lua number. In this cases generic version cannot be used and overloaded name should be used.
Trying to work a solution, suggestions are welcome.
Since ImVector stuff was erased, how do we use void ImFontGlyphRangesBuilder_BuildRanges(ImFontGlyphRangesBuilder* self,ImVector_ImWchar* out_ranges)
now?
Hello, I'm trying to compile LuaJIT-ImGui to use with Love2d and I ran to a problem when trying to compile it.
I did manage to compile LuaJit-SDL2 but when I run the following command from a folder inside LuaJIT-ImGui folder I get an SDL_INCLUDE-NOTFOUND
error
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DIMPL_GLFW=no -DSDL_PATH="C:\Users\Henrique\Documents\dev\lua\LuaJIT-SDL2\SDL" -DLUAJIT_BIN="C:\Users\Henrique\Documents\dev\lua\luajit\src" ..
here's the full error:
-- Building for: Visual Studio 16 2019
-- The C compiler identification is MSVC 19.28.29913.0
-- The CXX compiler identification is MSVC 19.28.29913.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Deprecation Warning at CMakeLists.txt:2 (cmake_minimum_required):
Compatibility with CMake < 2.8.12 will be removed from a future version of
CMake.
Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.
-- SDL_PATH defined as C:\Users\Henrique\Documents\dev\lua\LuaJIT-SDL2\SDL
CMake Error at C:/Users/Henrique/Documents/dev/lua/LuaJIT-SDL2/SDL/SDL2Config.cmake:1 (include):
include could not find requested file:
C:/Users/Henrique/Documents/dev/lua/LuaJIT-SDL2/SDL/SDL2Targets.cmake
Call Stack (most recent call first):
CMakeLists.txt:133 (FIND_PACKAGE)
-- sdlfound
CMake Warning (dev) at CMakeLists.txt:135 (get_target_property):
Policy CMP0045 is not set: Error on non-existent target in
get_target_property. Run "cmake --help-policy CMP0045" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.
get_target_property() called with non-existent target "SDL2::SDL2".
This warning is for project developers. Use -Wno-dev to suppress it.
-- sdlinclude is SDL_INCLUDE-NOTFOUND or
-- sdlinclude2 is
-- Configuring incomplete, errors occurred!
See also "C:/Users/Henrique/Documents/dev/lua/LuaJIT-ImGui/build/CMakeFiles/CMakeOutput.log".
any help is appreciated!
Is there perhaps any chance I could get some guidance on how to make this work with DirectX9? I got the LuaJIT-Window
release from anima, and have been trying to understand how everything works. So far I've tried creating the implementation functions in sdl.lua
, defining them in cdefs.lua
, and then modifying minimal_sdl.lua
to use the new implementation. After doing so I was met with the following error, where I've been stuck since:
luajit.exe: ...LuaJIT-Window-0.2b-Win32\LuaJIT-Window\lua\imgui\sdl.lua:317: cannot resolve symbol 'ImGui_ImplDX9_Init': The specified procedure could not be found.
stack traceback:
[C]: in function '__index'
...LuaJIT-Window-0.2b-Win32\LuaJIT-Window\lua\imgui\sdl.lua:317: in function 'Init'
examples/LuaJIT-ImGui/examples/minimal_sdl_dx9.lua:34: in main chunk
[C]: at 0x00402d26
I'm wagering that I would need to integrate the new DX9 implementation calls into cimgui_sdl.dll
but I am lost how I would go about doing that. Is my current approach appropriate or do I need to go about this in a different way? If I'm on the correct path, how do I integrate the new implementations into cimgui_sdl
?
Here's the additions to sdl.lua
and cdefs.lua
respectively for reference:
-- sdl.lua
-- Code placed right after M.Imgui_Impl_glfw_opengl2 = setmetatable({},Imgui_Impl_glfw_opengl2)
local Imgui_Impl_SDL_DX9 = {}
Imgui_Impl_SDL_DX9.__index = Imgui_Impl_SDL_DX9
function Imgui_Impl_SDL_DX9.__call()
return setmetatable({ctx = lib.igCreateContext(nil)},Imgui_Impl_SDL_DX9)
end
function Imgui_Impl_SDL_DX9:Init(window, device)
--self.window = window
lib.ImGui_ImplSDL2_InitForD3D(window);
lib.ImGui_ImplDX9_Init(device);
end
function Imgui_Impl_SDL_DX9:Destroy()
lib.ImGui_ImplDX9_Shutdown();
lib.ImGui_ImplSDL2_Shutdown();
lib.igDestroyContext(self.ctx);
end
function Imgui_Impl_SDL_DX9:NewFrame()
lib.ImGui_ImplDX9_NewFrame();
lib.ImGui_ImplSDL2_NewFrame();
lib.igNewFrame();
end
function Imgui_Impl_SDL_DX9:Render()
lib.igRender()
lib.ImGui_ImplDX9_RenderDrawData(lib.igGetDrawData());
end
M.Imgui_Impl_SDL_DX9 = setmetatable({},Imgui_Impl_SDL_DX9)
-- cdefs.lua
cdecl = cdecl .. [[
-- Already included code here...
bool ImGui_ImplDX9_Init(IDirect3DDevice9* device);
void ImGui_ImplDX9_Shutdown();
void ImGui_ImplDX9_NewFrame();
void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data);
]]
Thank you for your time, and great work on making this binding, I see how much work you've put into this.
First, thank you for your excellent work! I've started using these bindings for writing quick GUI apps on a handheld Linux device, it's very handy to have.
I just wanted to report a tiny typo in CMakeLists.txt, BAKENDS_FOLDER
should obviously be BACKENDS_FOLDER
.
Here's a patch:
patch.txt
@BrutPitt
Hi Michele,
As mat4_cast is returning a user defined type non C compatible I used what I have done in cimgui
9c85543
But I can check in https://github.com/sonoro1234/LuaJIT-ImGui/blob/master/examples/widgets_sample.lua that the values returned get garbage values after some time (I guess that when the Mat4 is destroyed on ImGuIZMO.quat module)
But this is strange as I would expect the values are copied to my provided struct in https://github.com/sonoro1234/LuaJIT-ImGui/blob/master/extras/imGuIZMO.quat.cpp#L28
but perhaps there is no copy contructor ? (My C++ skills are low)
What do you think that should be done?
Update: the problem seems to be on the LuaJIT side of things (in the C side I even tried memcopy and did not solve the issue)
Thanks
Can you please give instructions on how to compile for linux?
Hello,
I've been considering changing some of the low-level flags, e.g. think ImGuiWindowFlags
, ImGuiTableFlags
etc. to use 64-bit integers down the line.
Do you think that would cause issues with
Thank you!
I understand that I ask, perhaps a stupid question. but how to collect the contents of the archive from the LuaJIT binding to imgui 1.62 imgui_release.rar only for version 1.71
branch anima - master
love 11.3
commit f69b3cf
This time I needed to build for windows, maybe I did something wrong but the "make install" didn't work for me, I guess that's because I have msvc, so I did the build via VS, here's the dll problem when I run.
cimgui_sdl.zip
How about adding support for https://github.com/thedmd/imgui-node-editor
I would like to use this project in conjunction with my internal lua binding via cimgui, so not exactly the same project. I tried to do the generation steps myself and failed miserably.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.