views:

389

answers:

1

Hi,

I'm looking into adding scripting to my C# application. I've been debating between Lua and C# (through CSharpCodeProvider).

Regardless of which language I use, I need the script to be able to access/manipulate objects/arrays in my main application. With C# I should be able to expose my objects and interface functions without too many issues.

However, with Lua it seems like I'll only be able to access the application objects through exposed functions. I can't see how I could have a non-chunky interface to, for example, arrays. I'd either need Array1Set(index, value)/Array1Get(index) functions or ArraySet(array_no, index, value)/.... Is there an elegant way to implement this? I don't want to copy the arrays to the Lua machine, manipulate it, then pull it back into my application.

Thanks

+3  A: 

You should take a look at the LuaInterface project, which supports full integration between Lua and .NET. Ask google for more information about LuaInterface to find lots of useful pages of discussion, samples, and ideas.

The general method of sharing objects between Lua and any application in any language is to define the __index() and __newindex() metamethods (and possibly others) of a userdata containing either the object instance itself (letting Lua's GC manage the object's lifetime) or a pointer to the instance (which requires careful cooperation with the GC). The metamethods allow Lua code to manipulate fields of the object as if they were stored in a Lua table.

RBerteig
Great thanks, this is what I was looking for! My googling didn't find LuaInterface.
Aaron