Jump to content
  • Advertisement
Sign in to follow this  

passing table from C++ to Lua

This topic is 3564 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

Hi, I'd need a simple example to correct my understanding about the topic a bit. The Lua docu doesn't seem to talk a lot about that topic or I'm unable to find it For now I have this: C++ part:
HAPI_get_agent_state_by_name(lua_State* ls)
  	if (!lua_isstring(ls, 1) )
		lua_settop(ls, 0);
		return 0;

	std::string agent_name = lua_tostring(ls, 1);
	lua_settop(ls, 0);

        Engine::Agent agent( /*retrieve correct agent stuct*/ )

        //create table to be retrieved from Lua-side
        //for a simple test just the x part of position
	lua_pushstring(ls, "pos");
	lua_pushvalue(ls, -2);
	lua_settable(ls, -4);
	lua_pushnumber(ls, 1);
	lua_pushnumber(ls, agent.Position3D()[0]);
	lua_settable(ls, -3);

	lua_pop(ls, 1);
	return 1;

Lua part:
HAPI_print_string("test\n");  --that works
HAPI_print_string(t[pos][1]); --nothing

It prints nothing. Can anybody tell me what I'm doing wrong? Thank you in advance!

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!