Libui: Lua binding

Created on 20 May 2016  路  9Comments  路  Source: andlabs/libui

Not really an issue, more of a note: I've started writing a Lua binding to libui, if I find the time and discipline to get something working I'll point to the branch here and/or put up a pull request.

All 9 comments

I'm not sure if I want to host bindings as part of the main repository. Is there any advantage to doing so from a Lua programmer standpoint?

A LuaJIT binding would make sense to be in the repo since it could be housed in a single .lua file, I don't see much benefit in including a PUC Lua binding in though.

In Lua world, everyone implements their own :-). Lets see what kind of bindings there will be. There is no single answer. One might want to make bindings 1:1, the other guy may want to offer more Luafied bindings (e.g. something that is not available in C, but what makes sense in Lua).

I was also thinking about making LuaJIT bindings just for fun, and I have little interest in PUC Lua bindings, but I have done it in the past, and made both for example to CoolProp project. I think the best approach here is to make this bindings in their own separate repositories, and if something comes up as as winner, that could be considered as an official... and to be included to the main product. Until then, let's see what comes up?

Seems fair.

The advantage of custom bindings over FFI is a more Lua-ish API which allows for friendly chaining and object access. This is what I have working now:

win = ui.NewWindow("Hello", 320, 200, false):SetChild(
   ui.NewGroup("Group"):SetMargined(10):SetChild(
      ui.NewVerticalBox():Append(
         ui.NewButton("Foo"):OnClicked(function(name)
            print("This is " .. name)
         end, "Foo")
      ):Append(
         ui.NewButton("Bar")
      ):Append(
         ui.NewSlider(0, 100):SetValue(50)
      ):Append(
         ui.NewSpinbox(0, 100):SetValue(50)
      ):Append(
         ui.NewProgressBar():SetValue(10)
      ) 
   )    
):Show()

Some choices I made:

  • All top level functions are in the table returned by require
  • New objects are created with ui.NewType()
  • All uiTypeMethod() functions are accessible as object:Method() calls
  • All Set() methods return the object itself, which allow for chaining like s = ui.NewSlider(0, 10):SetValue(5):OnChanged(fn)

The binding comes in a single C file, no header files needed. It is of course up to you if you want to include the binding (or any language bindings) in your repo, the reason I posted this issue is just to let people know work is in progress, in case anyone else decides to do the same.

LuaJIT ffi bindings are rarely just "bind and go" -- there's usually always a Lualike wrapper on top of it. I can replicate all of that functionality in one .lua file with Luajit

Sure, true.

Anyway: for anyone interested in a Lua binding that works in both LuaJIT and PUC Lua, I've put up the code so far at https://github.com/zevv/libuilua.

Work in progress, of course.

Pietro, thanks for the lib, simple and sweet!

Maybe instead of hosting in this repo, it'd make sense to keep a file with a list of bindings for different languages (this seems the approach taken by a lot of projects). I also have a C# binding that I'm just completing, so that would be something that could also be listed there.

Closing this issue now that bindings exist.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andlabs picture andlabs  路  11Comments

kainjow picture kainjow  路  4Comments

kenchangh picture kenchangh  路  5Comments

andlabs picture andlabs  路  9Comments

justasmalinauskas picture justasmalinauskas  路  5Comments