如何在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;
}

原文链接 https://stackoverflow.com/questions/71324996

点赞