Lua如何将变量从lua推送到C++
你好,我正在尝试将变量从 Lua 推送到 C 函数,我该怎么做?我已经在 Lua 端生成了一个 C++ 对象,但想向该对象函数发送一个数字。但我得到:使用以下字符串加载脚本时出错:
player.lua:2: attempt to index a function value (local 'myPlayer')
player.lua
local myPlayer = Player.new(69)
myPlayer.testing(myPlayer, 24069)
player.cpp
int player_test_pos(lua_State* L)
{
player* myPlayer = l_CheckPlayer(L, 1);
myPlayer->setPos({ 10, 0, 30 });
int ok = lua_istable(L, 1);
std::cout << ok << std::endl;
ok = lua_isnumber(L, 2);
std::cout << ok << std::endl;
return 0;
}
Hi I am trying to push variables from Lua to a C function, how would I do that? I have generated a C++ object on Lua side but want to send a number to that the objects function. But I get: Error when loading script with following string:
player.lua:2: attempt to index a function value (local 'myPlayer')
player.lua
local myPlayer = Player.new(69)
myPlayer.testing(myPlayer, 24069)
player.cpp
int player_test_pos(lua_State* L)
{
player* myPlayer = l_CheckPlayer(L, 1);
myPlayer->setPos({ 10, 0, 30 });
int ok = lua_istable(L, 1);
std::cout << ok << std::endl;
ok = lua_isnumber(L, 2);
std::cout << ok << std::endl;
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论