- Due to the immediate mode nature of
egui, the scripts need to run every frame (average of 60 fps atleast). - Ui code creates lots of temporary
use onceobjects, which means lots of garbage collectable objects for a reasonably complex ui script. It is also expensive to create/recreate these objects every frame.- Builder pattern creates a struct for every container/widget. eg:
Window::new("hello")orRichText::new("text").color(egui.blue)etc.. - return values of widget
uifn likeResponsealso create userdata objects. - each
&mut Uineeds to create a new userdata object to bind that reference to. - Even value types like
Rectwill need to be userdata.
- Builder pattern creates a struct for every container/widget. eg:
- Due to a large amount of function calls between native host egui and the script, JIT also sucks at optimizing this.
- All the closures also require jumping between host and guest scopes which have some "setup"/"teardown" costs
This project might still work for some people, and I would encourage them to fork this repo. But I would like to experiment with retained mode toolkits now, where you only scripts on events.
egui bindings for mlua.
Just look at the example for basic usage. You can play with the web version live at https://coderedart.github.io/luaegui/
There should be a window called Script Editor where you can edit the lua code live within egui.
After editing the code, just click the run button on top to execute that code in the lua vm.
If there was any error, it will be printed to stdout/console(on web).
Below the code editor, you can see how long the gui_run fn takes every frame.
Every frame, the example will try to call the gui_run fn (if it exists) and gives it egui context as the argument.
If the fn fails for some reason, the error will be printed to stdout/console.
We provide a global table called egui which contains most constants + types + functions to be used by lua scripts.
for example, you can create a Window using local window = egui.window.new("my window title");
Because we don't really have a way to properly document host api in mlua yet, we will do this manually. For now, we provide a type definition file (WIP) egui.d.lua.
- Install
Luau Language Serverextension byJohnnyMorganzin vscode - copy
egui.d.luafile from thi repo to your lua project folder - In the settings Ui
luau-lsp.types.definitionFiles, add the fileegui.d.lua - Now, you have autocompletion, as well as linting (to a reasonable extent) when you want to use egui.