darkshin
New old member
- Joined
- Dec 14, 2010
- Messages
- 231
- Reaction score
- 22
Hello Guys!!
I am having a trouble trying to get a Lua table at a C++ Function, in luascript.cpp.
Here is the code:
Lua file
C++ Function
I am getting 0 at every"getField", so I assume that I am doing it wrong. Can anyone help me make it workout?
I am having a trouble trying to get a Lua table at a C++ Function, in luascript.cpp.
Here is the code:
Lua file
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local recipe = Recipe()
local items = {
item1 = {2157},
valor1 = {50},
item2 = {0},
valor2 = {0},
item3 = {0},
valor3 = {0},
item4 = {0},
valor4 = {0},
item5 = {0},
valor5 = {0}
}
recipe:setRecipeItem(items)
end
C++ Function
Code:
int LuaScriptInterface::luaRecipeSetRecipeItem(lua_State* L)
{
RecipeHandler* recipe = getUserdata<RecipeHandler>(L, 1);
uint32_t items[5][2] = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } };
lua_getglobal(L, "items");
for (uint8_t i = 1; i < 5; ++i) {
if (getField<uint32_t>(L, 2, "item" + std::to_string(i)) == 0 || getField<uint32_t>(L, 2, "valor" + std::to_string(i)) == 0) {
std::cout << "[Error - LuaScriptInterface::SetRecipeItem] Null filed at: " << std::to_string(i) << std::endl;
break;
}
else {
items[i][1] = getField<uint32_t>(L, 2, "item" + std::to_string(i));
items[i][2] = getField<uint32_t>(L, 2, "valor" + std::to_string(i));
}
}
if (!isTable(L, 2)) {
pushBoolean(L, false);
return 1;
}
else {
if (recipe) {
std::cout << "[LuaScriptInterface::SetRecipeItem] Sending Values: " << std::to_string(items[1][1]) << std::endl;
recipe->setRecipeItem(items);
}
else {
lua_pushnil(L);
}
}
return 1;
}
I am getting 0 at every"getField", so I assume that I am doing it wrong. Can anyone help me make it workout?