[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Metatables are "hard" (Re: Question about __index and classes)
- From: Josh Simmons <simmons.44@...>
- Date: Mon, 29 Aug 2011 14:54:48 +1000
On Mon, Aug 29, 2011 at 7:54 AM, oliver <firstname.lastname@example.org> wrote:
> I've had same experience. One issue is that if you program in multiple
> languages you can't remember all the details (or maybe I'm just getting old
> ;) Plus a lot of exposing C/C++ classes and functions to Lua is repetitive,
> boiler plate code, and it's easy to make indexing mistakes when using the
> Lua stack. So I use SWIG so I don't have to worry about __index, stack
> indices etc. I create pure c++ libs then let SWIG do all the binding to
> allow me to use them from Lua. And when I need to script a C++ application
> with Lua (rather than extend Lua with a C++ lib), I use SWIG in conjunction
> with an OO wrapper lib (plug-alert: like lua-icxx, which I wrote; see
> Performance impact is oft mentioned as main reason for *not* using a code
> generator like SWIG or tolua++. That makes me smile because a C++ compiler
> is a code generator (generates machine code). Surely you can write assembly
> that is more efficent than C++. Maybe. Once in a rare while. With more time.
> More bugs. And less maintainable and understandable. Also, IME "realworld"
> apps do way more than run Lua scripts (from C++) or call c++ lib from Lua;
> such as file and network access etc. And design decisions tend to have a
> much greater impact, like how often do game entities get (re-)created, how
> often do you run queries on a database, how much state you store locally vs
> on server, use of caching etc. So the impact of SWIG-generated code over
> rolling my own has been negligeable in performance and significantly
> positive in implementation time and maintainability.
> Note: I have no stake in SWIG. I'm just glad it supports Lua, yet I get the
> impression many people who find __index etc a pain don't know about it.
> On Sun, Aug 28, 2011 at 2:45 PM, Mark Hamburg <email@example.com> wrote:
>> This thread plays a bit to a message I started a while ago and never
>> finished. Metatables are "hard" -- particularly for people coming from
>> backgrounds in OOP languages. This message is not about potential changes to
>> Lua but rather is an attempt to understand why people get confused so often.
Personally I don't think this helps, using a binding generator just
papers over the cracks in your knowledge resulting in bigger issues
further down the line.
The Lua manual is beautifully succinct such that it serves as a
perfect reference manual (hey look at the name!) for filling in
knowledge gaps, the best way to deal with these issues is to use the
index or old control+f on that bad boy and learn what you need to know
when you need to know it.
__newindex is an odd wording though I'm not sure it'd be really worth
changing at this point.
I'd also note there's no real reason for automatically generated
bindings to be any slower than manually generated ones, provided the
layer doing the generating isn't rubbish. You might want to use
lighter constructs like lightuserdata in some areas but that's
irrelevant to the ordinary userdata + meatatable generation case.