• Advertisement
Sign in to follow this  

Lua table exposing issues

This topic is 3644 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 didn't know if this was the right place to ask (I'm hoping someone knows lua :P), but i'm having having trouble trying to get table entries (declared in lua) from cpp code. I know its possible so its most likely bad syntax on my part. i'll just paste the code and scripts i'm using. (TestScene.lua)
uniquename = {}
resourcename = {}
size = {}
type = {}
textures = {}
detail = {}
function TerrainEntry(b) 
	uniquename[b.uniquename] = true
	resourcename[b.resourcename] = true 
	size[b.size] = true 
	type[b.type] = true 
	textures[b.textures] = true
	detail[b.detail] = true
     	uniquename = "Terrain-1",
      	resourcename = "Resources/Terrains/height128.raw",
      	size = 128,
      	type = 0,
	textures= {"Resources/Materials/new1.tga","Resources/Materials/new2.tga"},
	detail = "Resources/Materials/DetailMap1.tga"
I know that the above scripts work, because i've tested printing out the values after i call "dofile" and they display correctly. The problem im having comes when I try to expose these values to the stack so i can access them from cpp. (inside cpp functions)
void LoadFile(char *fileName)
	m_scriptor->RunScriptFile("TestScene.lua"); //Hard-coded for now

	std::string temp = m_scriptor->GetTableString("uniquename");
(The above 'GetTableString' function calls this code below, where 'key' is the char* "uniquename")
	lua_pushstring(L, key);

	lua_gettable(L, -2);

	if(!lua_isstring(L, -1))
		std::string err("<LuaPopStringFieldFromTable> Cannot retrieve: ");

		//throw std::runtime_error(err + key);

	std::string s = lua_tostring(L, -1);

	lua_pop(L, 1);   // <-------- IT DIES HERE

	return s;
If anyone could be of any help i would be very thankful, im so confused.

Share this post

Link to post
Share on other sites
don't have lua refman around here, but you must do something like:

lua_push(L, "tablename");

you should get the result on top of the stack

Share this post

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

  • Advertisement