尝试调用函数但没有任何反应。

我似乎无法解决它,而我在课堂上接收的示例与我在网上看到的Lua示例看起来非常不同。

我将以下代码从课堂上复制到我的cpp文件中:

#include "InputManager.h"
#include <iostream>
#include <string>

InputManager* InputManager::instance = NULL;

int LuaExample_OutputInt(lua_State *L) {
    int argc = lua_gettop(L);

    if (argc == 1) {
        const lua_Integer value = lua_tointeger(L, 1);
        std::cout << "Value: " << value << std::endl;
    }
    return 1;
};
REGISTER_LUA_FUNCTION(LuaExample, OutputInt)

void InputManager::update() {

    std::string command;

    std::cout << "Enter LUA command:" << std::endl;
    std::getline(std::cin, command);

    LuaState::getLuaState()->executeLuaString(command.c_str());
}

程序编译没有问题,也没有显示任何错误,但程序在我输入值后就结束了,它从未进入LuaExample _OutputInt部分。我做错了什么?

点赞