lua-users home
lua-l archive

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


On Tue, Apr 21, 2015 at 2:40 PM, Andrew Starks <andrew.starks@trms.com> wrote:
>
> I guess I was approaching this differently than I would have
> approached C++, but I shouldn't have. I don't program in C# and I'm
> not writing the binding, so that's probably why I see it as "other".
>
> >From looking at your repo (thank you!), it seems like it may be
> similar to the choice that you face in C++:
> 1: basically use the stack as is, but wrap it in a simple "lua" object
> 2: using someone's library in an attempt to make using code in the
> other language easier
>

Essentially yes. In C# things are a bit more interesting because
without templates you're forced to generate the marshalling code at
runtime (short of using something like SWIG) which can cause issues.

It's also worth noting there's a decent middle ground if you just
abstract the stack operations behind something more language friendly
and still allow low level Lua API access for anything more involved.

(https://github.com/jsimmons/lcpp#example-codes An API along these lines)

Ultimately it depends on how you see your barrier APIs looking as to
what level of magic is appropriate.

> I normally don't like the second approach, but i feel like it might be
> pragmatic, in this case. I'm fuzzy about how to deal with C#'s garbage
> collection, but that is almost certainly due to me knowing next to
> nothing about C#. I have done enough reading and asking/listening to
> know about P/invoke.

Dealing with C#'s garbage collection is not too difficult if you just
keep a reference to a given object whilst the opposite side of the
interop layer also maintains one. Lua objects in C# can be represented
by a state pointer and lua_Ref. C# objects in Lua can be represented
by a generic userdata and a container of objects in C#.

You can obviously get more involved than that but that's the simplest
way to do things generically.


Cheers,
Josh.