Jump to content
  • Advertisement
Sign in to follow this  
SiS-Shadowman

Passing a pointer to a class to LUA

This topic is 3995 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've a problem: I've tried out tolua++ to have classes in LUA, but the extra building process and the extra cleaned header file just doesn't feel comfortable. So I just downloaded luna, wich seems to be easier for me. But I'm not shure how I can pass a pointer to a class from c++ to lua. I've got a class CNPC that gets exported to lua with luna. Currently, I'm just exporting one function (along with ctor/dtor). But calling GetPlayer() from within lua returns "test.lua:3: attempt to index global 'Player' (a userdata value)
--test.lua programm
Player = GetPlayer();
Player:test();

int GetPlayer( lua_State *L )
{
	int n = lua_gettop( L );

	if( n != 0 ) {
		lua_pushstring(L, "Incorrect argument to 'GetPlayer'");
		lua_error(L);
	}

	lua_pushlightuserdata( L, g_pPlayer );

	return 1;
}


What do I need to do?

Share this post


Link to post
Share on other sites
Advertisement
*edit*

Gah, I had this whole big post written out, but when I hit the reply button my browser hiccuped. When I was finally able to get back in here I found that my post was empty. I don't really feel like typing it all out again, sorry. However, if you download the lua player source code: http://luaplayer.org/staticpages/index.php?page=20070708120150241

Take a look at the macros in the luaplayer.h and how they're used in luagraphic.cpp to see an example of how to set metamethods to userdata

[Edited by - Merick Zero on August 14, 2007 7:36:03 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!