Itutorial
Legendary OT User
- Joined
- Dec 23, 2014
- Messages
- 2,330
- Solutions
- 68
- Reaction score
- 1,008
I need to create a c++ table using a table created and called from lua.
What im sending in lua
c++
What im sending in lua
Lua:
local playerList = {target:getId()}
local creature = Game.createUniqueNpc(name, pPos, playerList, 0, 1)
c++
C++:
int LuaScriptInterface::luaGameCreateUniqueNpc(lua_State* L)
{
// Game.createUniqueNpc(npcName, position, playerIdList [, extended = false[, force = false]])
Npc* npc = Npc::createNpc(getString(L, 1));
if (!npc) {
lua_pushnil(L);
return 1;
}
const Position& position = getPosition(L, 2);
std::list<uint32_t> list;
lua_gettable(L, 3); // Doesn't seem to work tried a lot of different things instead of this
while (lua_next(L, -1) != 0) { // Error here
std::cout << "Attempting to call values from table" << std::endl;
uint32_t tmpID = getNumber<uint32_t>(L, -1);
std::cout << "Called number value from table" << std::endl;
if (tmpID) {
list.push_back(tmpID);
std::cout << "Pushed number to list." << std::endl;
lua_pop(L, 3);
}
}
bool extended = getBoolean(L, 4, false);
bool force = getBoolean(L, 5, false);
Last edited: