|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
Problem to derive a base class in C++ or in LuaHello Everyone I'm writing to you because i've just tryied to use LuaBind, and i get a few basic things working : binding a function, binding a basic class. But i can't derive a class. To be more precise I can't derive in Lua a class defined in C++ ; and I can't even derive in Lua a class defined also in Lua. My C++ and Lua code is below
As I'm a complete beginner with LuaBind, I suppose my mistake is obvious, but I don't see it.
I'm using MSVC++ 9.0 on windows Vista. I've put in my project folder the lua and luabind include file. I've also put luabind source file. I link with lua51.dll.
Thanks in advance for your help
my C++ code is :
extern "C" { #include "lua.h" #include "lualib.h" #include "lauxlib.h" } #include "luabind/luabind.hpp" #include <iostream> using namespace luabind; using namespace std; int main() { lua_State *myLuaState = lua_open(); luaL_openlibs(myLuaState); open(myLuaState); int retLua = luaL_dofile(myLuaState,".\\Test.lua"); if (retLua !=0) { cout << "erreur dans l'éxécution LUA :"<< retLua << endl; } lua_close(myLuaState); return 0; }
my Lua code is :
class 'lua_testclass' function lua_testclass:__init(name) self.name = name end function lua_testclass:print() print(self.name) end a = lua_testclass('example') a:print()
class 'derived' (lua_testclass) function derived:__init() super('derived name') end function derived:print() print('Derived:print() -> ') lua_testclass.print(self) end b = derived('derived example') b:print()
In this code, if b is a lua_testclass, there is no error. Créez votre adresse électronique prenom.nom@... 1 Go d'espace de stockage, anti-spam et anti-virus intégrés. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ luabind-user mailing list luabind-user@... https://lists.sourceforge.net/lists/listinfo/luabind-user |
|
|
Re: Problem to derive a base class in C++ or in Luafrancois.chenebit@... wrote:
> As I'm a complete beginner with LuaBind, I suppose my mistake is > obvious, but I don't see it. [snip] > In this code, if b is a lua_testclass, there is no error. The __init function for derived doesn't take any arguments, so that's the first thing I'd fix. - Jim ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ luabind-user mailing list luabind-user@... https://lists.sourceforge.net/lists/listinfo/luabind-user |
|
|
Re: Problem to derive a base class in C++ or in LuaHello Jim Thank you for answering me, but it wasn't that. If I change my lua code to this :
function derived:__init(name) super(name)
It's still doesn't work
By the way, I've just copied the example in the site.
Does someone has another idea
Thanks in advance.
François > Message du 08/08/09 19:48 |
|
|
Re: Problem to derive a base class in C++ or in LuaHello again
I've tryied another time with a different lua code :
function derived:__init(name)
This code works. But if I uncomment the call to super, it doesn't. I've called super first as said in documentation. With this in mind, I've tryied another search on google for that problem. I've found a post by Daniel Wallin explaining that super has been deprecated. So with calling in my C++ code luabind::disable_super_deprecation(); My code works. I've read the documentation that is in the source, and it has another version than the one on the web site. I'll try that tomorrow to check that, but I'm confident. May be it could be wise to update documentation on web site. Thanks again for your help François > Message du 08/08/09 20:13 |
|
|
Re: Problem to derive a base class in C++ or in LuaThe Lua wiki gives nice examples of how to create derived classes in
the "Metatables - Classes" section: http://lua-users.org/wiki/SampleCode e.g. Yet Another Class Implementation: http://lua-users.org/wiki/YetAnotherClassImplementation ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ luabind-user mailing list luabind-user@... https://lists.sourceforge.net/lists/listinfo/luabind-user |
| Free embeddable forum powered by Nabble | Forum Help |