[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: C++ binding: arg errors
- From: "Jerome Vuarand" <jerome.vuarand@...>
- Date: Thu, 5 Oct 2006 10:11:29 -0400
C++ methods are compiled into functions with an extra first argument holding the "this" pointer, because ABIs are usually not object oriented and only support functions. It's not that strange to consider that first argument is this and actual first parameter of the method is in fact the second one of the equivalent function. It's especially natural in the context of a binding between an OO language (C++) and a non-OO language (Lua).
-----Message d'origine-----
De : lua-bounces@bazar2.conectiva.com.br [mailto:lua-bounces@bazar2.conectiva.com.br] De la part de Glenn Maynard
Envoyé : 4 octobre 2006 23:11
À : lua@bazar2.conectiva.com.br
Objet : C++ binding: arg errors
The Lua binding I'm using for C++ classes removes the "self" parameter from the stack. It's always passed to the bound class, after type checking. This allows arguments to be referenced more naturally, with the first argument at 1, rather than 2.
This causes a problem: it confuses luaL_argerror, since it expects the self parameter to be there; it subtracts one, giving the wrong offset for error messages (and "bad self" for errors on argument 1).
Any suggestions on how to deal with this? I can't simply change that function, since this only applies to arguments to these methods, not library calls. I don't want to simply not do this; in the context where "self" has already been processed and passed as an argument, it's strange to have to address the first argument as 2, and there are hundreds of bound methods that would be affected.
--
Glenn Maynard