On 8/4/2014 12:32 AM, Andrew Starks
wrote:
On Sunday, August 3, 2014, Littlefield, Tyler < tyler@tysdomain.com> wrote:
Hello all:
I'm working on this project:
http://github.com/sorressean/aspen
and want to seriously revamp scripting. All of my game-objects
are objects, so I'd like to wrap these in Lua and provide
inheritance so that I just need to add methods and they can
override etc. I have a few ideas and I'm hoping people can
help with some solutions:
1) I'd love to have garbage collection actually free up the
object.
2) Inheritance: I never deal with multiple inheritance, so
that's not an issue.
I'm having a really hard time writing this, however. Are there
any examples that show how to pull this off the right way? I'd
ultimately be happy with two classes, one of which inherits
the other so I can see how best to do that in the API.
I'd greatly appreciate any information/help. TIA,
--
Take care,
Ty
http://tds-solutions.net
He that will not reason is a bigot; he that cannot reason is a
fool; he that dares not reason is a slave.
Maintaining objects that live in both Lua and C / C++ is
hard. At the API intersection, we've had more success by
keeping the system language abstractions simple and dumb. We
ended up doing extra work to unwind the fanciness from C++,
only to remake the-same-but-different abstractions in Lua.
If you can make your C binding feel more procedural-y and
less object-y, then your Lua objects will be extremely simple
to make. If you're like me, perhaps the biggest problem is
over-doing the object features and the interface. Lua almost
begs you to write your own object system and it's hard to know
when to stop, until you've done it a few times.
Hello:
Thanks a lot for the info. I'm actually scrapping the current system
and trying to rework what I have. Basically right now i have one
main issue I'd like to solve:
I have two objects (many more, but this will do): Entity and Player.
Entity is any in-game object, it holds name, contents etc. Player is
pretty self explanitory. Right now, Entity has methods like GetName,
GetLocation etc. Player inherits that, so I need some way of
modeling that: allowing a user to call GetName on a player. I
planned on using inheritance for that because it frees me from
writing the chain of inheritance methods over for every new object.
How have people handled this in the past? If there's a cleaner way
(short of using classes), I'd love to do it that way. My second
issue really was that I could set up these methods and attach them
to userdata somehow, but I'd need to somehow model inheritance with
those. E.g: is GetName being called on a player? If so, there would
be some way to look up that Player inherits entity and that feels
really messy to me.
Thanks,
Don't know if that helps. I imagine you're not going to
re-write tons of C code. But consider just simplifying things
at the binding/intersection between the two.
-Andrew
--
Take care,
Ty
http://tds-solutions.net
He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave.
|