how to derive lua class from c++ class

"kunshou" <[email protected]> Mon, 9 Jan 2012 01:20:23 +0800
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
 

 

发件人: kunshou [mailto:[email protected]] 
发送时间: 2012年1月2日 2:24
收件人: [email protected]
主题: how to derive lua class from c++ class

 

Hi

I just stepped into luabind 0.9.1. I am trying to derive a class in lua from
a c++ class.

My c++ class looks like

class testclass

{

public:

    testclass(const char* s): m_string(s) 

    {std::cout << m_string << " @created." << std::endl;}

    void print_string() { std::cout <<"testclass:" <<m_string << "\n"; }

 

private:

    std::string m_string;

};

 

The lua code

 

class 'derivedclass' (testclass)

  function derivedclass:__init(name)

    testclass:__init(name);

  end

 

testderivedclass = derivedclass("hi")

testderivedclass:print_string()

 

when I run this lua code in c++ using luaL_dofile, the program always
crashes.

 

Could anyone please tell what’s wrong with my code, or give a right
example?

 

Many thanks

------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox

_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user