-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|558|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Snippet Home -> Misc


 
Cower
Created : 29 November 2009
Edited : 29 November 2009
Language : Blitz Max

Lua-Scriptable Type

Small type that allows for easily associating Lua functions to objects

This is sort of a rudimentary example of using LuGI to bind functions to objects in Lua. It could be expanded upon (e.g., binding closures for different messages and such), but it works well enough for the sake of example.

Speaking of examples, here's some code and a script to accompany it:

woop.bmx


woop.lua


scriptable.bmx


Bear in mind that this requires the most recent version of LuGI's master branch, since I added a handy method for binding glue functions to types. This was already possible, it just required you to be aware of the private API, which seems like a bad idea to me since it's only documented in the headers.

This could also be easily ported to some other languages (C#, C++, maybe Objective-C and Java, etc. - basically, any language that is fairly flexible). I could probably cut out the use of LuGI, but LuGI makes working with objects very easy, so I choose to use it over making it more complex but completely standalone.

 

Comments