【发布时间】:2025-11-23 14:15:01
【问题描述】:
我的代码(部分) c++:
lua_register(L, "GetPosition", lua_GetPosition);
int lua_GetPosition(lua_State* L)
{
Entity e = static_cast<Entity>(lua_tointeger(L, 1));
TransformComponent* trans = TransformComponentPool.GetComponentByEntity(e);
if (trans != nullptr)
{
lua_pushnumber(L, trans->transform->position.x);
lua_pushnumber(L, trans->transform->position.y);
lua_pushnumber(L, trans->transform->position.z);
}
else
{
lua_pushnumber(L, 0);
lua_pushnumber(L,0);
lua_pushnumber(L, 0);
LOG_ERROR("Transform not found");
}
return 1;
}
卢阿:
local x = 69
local y = 69
local z = 69
x,y,z = GetPosition(e)
print("xyz =",x,y,z)
我预计“xyz = 1.0 1.0 1.0” 我得到“xyz = 1.0 nil nil”
什么是正确的方法让 lua 看到所有的返回值?
【问题讨论】:
-
您需要返回您推送的值的数量:
return 3。 -
你可以简单地写
local x, y, z = GetPosition(e)btw。这里不需要用值初始化 x,y,z。