Lua 5.1.3 bindings with wrapper classes and mixins released

Matthias Walter Matthias.Walter at st.ovgu.de
Tue Sep 9 23:50:59 PDT 2008


Dejan Lekic Wrote:

> Mr. Walter, what are advantages of this binding over the DLUA project? 
> More about it: http://code.google.com/p/dlua/ .
> 
> Kind regards

To clarify, what we talk about: It's the current version of Lua in the bindings project (http://dsource.org/projects/bindings/wiki/LuaLib). I'll give a short list of features:

1. You have OOP wrappers for LuaState and LuaBuffer. This is more a style feature for all those of us that like OOP. But this enables some other featuers, as you will see.
2. The wrappers can be used with more D-ish datatypes like char[] instead of \0-terminated arrays.
3. One might register functions and methods to a given LuaState, which makes them available in Lua, if they return int and take a LuaState. Also constructors may be registered, but of course they should not return int :) The registrations are done via D code mixins. At runtime, one can wrap a class, which makes the LuaState push a userdata, representing this class, onto the stack of this state. So the D-Object is now also available in D. If a constructor is registered, this works vice versa, so Lua code might create D objects, too. Such an object in Lua will have all the methods (via metatables) which were registered before, so you can easily backend your Lua datastructures in D.
4. All lua native types can be saved in special D objects which make them serializable. If you want to send Lua runtime data over the wire by your Lua client, one can easily dump a whole table with all its data.
5. Have you ever tried to raise an exception in a C or D function, which was called by Lua code? Normally, you'll get a segfault, because error handling is done va getjmp and longjmp internally by the lua library which breakes exception handling in D. My Lua wrappers will catch exceptions, add some information, where it was caught, save everything, let the library longjmp and raise it again. In my lib, this is called exception forwarding.

I hope this illustrates some advantages of the OOP approach.

best regards
Matthias Walter


More information about the Digitalmars-d-announce mailing list