Lua

lua_State* lua_state; //定义对象
lua_state = luaL_newstate();

    luaL_openlibs(lua_state);
    if(lua_state == NULL)
    {
        LOGERROR("错误:初始化lua环境失败!");
        m_error = "错误:初始化lua环境失败!";
        return false;
    }
    luabridge::getGlobalNamespace(lua_state)
            .beginNamespace ("kbd")
            .addFunction ("getDataByIndex",&CCalcLua::getDataByIndex)
            .endNamespace ();
  
  
lua_settop(lua_state,0);
    try
    {
        if( LUA_OK != luaL_dostring(lua_state,m_content.toStdString().c_str()) )
        {
            LOGERROR("错误:验证公式正确性失败!");
            m_error ="错误:验证公式正确性失败!";
            return false;
        }
    }catch(std::exception &ex)
    {
        m_error = QString::fromStdString(ex.what());
        LOGERROR("错误:验证公式正确性异常[%s]!",ex.what());
        return false;
    }

  //执行
  luabridge::LuaRef objFunc = luabridge::getGlobal(lua_state, m_name.toStdString().c_str());

        luabridge::LuaRef ret = objFunc();

  ret//需要解析

  
lua_close(lua_state);//释放
不为其他,只为快乐!
原文地址:https://www.cnblogs.com/1521299249study/p/12083306.html