• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

patrickriordan/imgui_lua_bindings: Function bindings for ImGui in lua

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

patrickriordan/imgui_lua_bindings

开源软件地址(OpenSource Url):

https://github.com/patrickriordan/imgui_lua_bindings

开源编程语言(OpenSource Language):

C++ 89.8%

开源软件介绍(OpenSource Introduction):

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++

    IMGUI_API bool          RadioButton(const char* label, bool active);

How to call function in 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++

    IMGUI_API void          ShowTestWindow(bool* opened = NULL);

How to call function in lua

opened = imgui.ShowTestWindow(opened)

This can make some functions a bit weird. For example Begin.

Function definition in 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)

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++

    IMGUI_API void          SetNextWindowPos(const ImVec2& pos, ImGuiSetCond cond = 0);

How to call function in lua

imgui.SetNextWindowPos(100, 50)

DrawList functions:

All functions that operate on drawlists are called with the prefix DrawList

Function definition in C++

    IMGUI_API void  AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness = 1.0f);

How to call function in 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.

ImGui::SetNextWindowSize(ImVec2(550,680), ImGuiSetCond_FirstUseEver);
ImGui::Begin("Demo", p_open, ImGuiWindowFlags_ShowBorders);
ImGui::End()
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!




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
poga/actix-lua: Safe Lua Scripting Environment for Actix发布时间:2022-08-16
下一篇:
jonstoler/class.lua: object-oriented library for lua发布时间:2022-08-16
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap