Hey guys!
I found Tiled (http://www.mapeditor.org/) quite a while ago (I was using Unity) and found it really useful.
I want to be able to load "tiled.lua" files into my C++ program.
I am using LuaBridge(https://github.com/vinniefalco/LuaBridge) to do most of the heavy lifting.
But now I am stuck.
Let me show you how a Tiled map looks in lua:
bigtable
{
version = "2.2.2.2.2"
luaversion = "0.0.0.0.1"
tilesets
{
name = "Rock"
...
name = "Grass"
}
layers
{
data{0,0,0,0,0,0,0,0,0,1,2,3,4}
...
}
}
So yeah it is a lot of information in a table.
Using LuaBridge you can use: getGlobal(luaState,"key") to get a handler to that key value and then cast it into the apropiate type.
But,how do I "get" things without using a name(a char*) just using an id for example like:
lua_State* L = luaL_newstate();
luaL_dofile(L, "../data/scripts/untitled.lua");
luaL_openlibs(L);
lua_pcall(L, 0, 0, 0);
LuaRef globalData = getGlobal(L, "globalData");
LuaRef someKey = getGlobal(L,2);//How to do this
I am not sure how it should be done :C
Sorry it the answer is really obvious but I can“t find it :C
You can't assign a value to a number in Lua.
While what you're asking is not clear (since it's impossible), assuming what you're looking for is to get the value in a table using a number as an index:
lua_getglobal(L, "global_table"); //Push the table to the top of the stack
/*
The following three lines are equivalent to this in Lua:
global_table[4] = 2000
*/
lua_pushinteger(L, 4);
lua_pushinteger(L, 2000);
lua_settable(L, -3);
//Push global_table[4] to the top of the stack
lua_pushinteger(L, 4);
lua_gettable(L, -2);
std::cout << lua_tonumber(L, -1) << std::endl; //Should print 2000
lua_pop(L, 2); //Remove the value and table from the stack