Lua Bindings

I’ve been updating how my Lua binding system works over the last few days. My original system was getting me in the shit with co-routines because I short sightedly stored a global Lua instance and accessed it from everything.

While this has worked, and is accessible, it does fuck me about in a lot of ways. Like I can only really have one Lua instance in each dll realm (menu, client, server). I’ve got no need to have more right now – but that’s not the point.

My old bindings looked like this..

ss (2013-03-13 at 04.37.28)

The calls to Get_Entity  and Get_Float are what are bumming me. They’re accessing globals.

So now my bindings are looking like this.

ss (2013-03-13 at 04.36.24)

The ‘lua’ variable is passed to the function from a function that the LC_Function macro creates. It’s no longer retrieved from a global – it’s retrieved from the lua_state that is passed by Lua to all function calls.

I also started documenting the functions in a way that I can parse with a PHP script, turn to JSON and automatically throw at the wiki. Something I really really wish I had done over the years for the 2,000 other functions.

6 thoughts on “Lua Bindings

  1. Garry have you looked at using code generators like tolua++ that can make these bindings much more easily just by reading your .h files?

  2. This is the same thing we have done in PHP for many years now, even the thread safety crap comes from there instead of using a global:

    http://lxr.php.net/

    And check for: ZEND_FUNCTION and some of the TSRM stuff, like TSRMLS_DC

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s