在C++中调用LUA字符串中的函数

我有一个从字符串中加载的C++函数。然后我想从lua中重新调用这个函数,但是出现错误:“调用尝试全局exm函数……”。我该如何在lua文件中重新调用它? 在C++文件中:


extern "C"
{
    #include "lua.h"
    #include "lauxlib.h"
    #include "lualib.h"
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

  int __declspec(dllexport) __cdecl luaopen_newtool (lua_State* L) {
        static const char * lua_code = "function exm()\n return true\n end";

        luaL_dostring(L ,(const char *)lua_code);
        return 0;
}

}

在LUA文件中:

require("newtool")
local exam = exm()
点赞