lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi all,

This is a Mono-compatible version of LuaInterface [1], which is a
binding of Lua to .NET.

Since 1.5.3, LuaInterface moved to a fully managed solution, where the
Lua C code was compiled as CIL, which was more convenient for
deployment with .NET applications, since it then only required a
single assembly and no messing around with native DLLs. Another reason
is that much of the overhead of going between Lua and C# is due to
P/Invoke, not reflection.  This is one of the conclusions of the
excellent article by Fabio Mascarenhas and Roberto [2]

This is however not the best solution for using LuaInterface for
general Lua scripting that needs to still be able to use existing Lua
binary modules, and was not an option for Mono, since gcc does not
have a standard CLI backend [3],

The background behind this effort is a general effort to bring Lua to
the popular Unity3D game editor by Alexander Gladysh and his company
LogicEditor (http://logiceditor.com). and this effort has been made
possible by his generous support.

The repository is here [4] which is the latest LuaInterface 2.0.3
modified to using P/Invoke to load the native Lua shared library.
There have been some fixes to property/field lookup and error
handling.

The suggested way to get things running is via the old-fashioned
./configure && make && ./install.  There are some installation notes
in the readme, but the key thing here is that you will need a Lua
shared library, the headers to compile the luanet.so stub and the Mono
compiler.

BTW, it still works on Windows, using the MS csc compiler (and if you
have .NET on your machine, you have csc.exe, which is a rare case of
MS giving away goodies with their operating systems)  This version is
much better suited for integration with Lua distributions, such as
LuaDist, and I will provide compatibility with that distribution in
due course. So this helps to complete the feature set of the original
Lua for Windows.

A nice example to show how to access Lua from C# code is here [5]

The cool thing about bindings to managed frameworks like Mono or Java,
is that you can easily access any libraries built for these platforms,
without having to write any extra binding code. So for instance, here
is _yet another way_ to use GTK+ from Lua:

-- hello-gtk.lua
require 'CLRPackage'
import ('gtk-sharp','Gtk')

Application.Init()

local win = Window("Hello from GTK#")

win.DeleteEvent:Add(function()
    Application.Quit()
end)

win:Resize(300,300)

local label = Label()
label.Text = "Hello World!"
win:Add(label)

win:ShowAll()

Application.Run()

(WinForms applications still run on Mono, but the aesthetics of the
result leave a lot to be desired.)

The worm in the apple is that some of the nicest features (like using
a Lua function as a delegate in this example) depend on run-time code
generation, and some popular platforms (like MonoTouch for iOS) don't
allow this.  There are however workarounds for this issue.

Thanks to Alexander and LogicEditor for their support; they are true
friends of Open Source for funding an MIT licensed project.

steve d .

[1] http://code.google.com/p/luainterface/
[2] https://github.com/stevedonovan/MonoLuaInterface/blob/master/doc/luainterface.pdf
[3] However, there _is_ an experimental gcc backend:
http://gcc.gnu.org/projects/cli.html
[4] https://github.com/stevedonovan/MonoLuaInterface
[5] https://github.com/stevedonovan/MonoLuaInterface/blob/master/tests/CallLua.cs