编译链接器文件以在Lua 5.2.1中嵌入C代码

时间:2015-01-26 07:58:38

标签: c lua lua-api lua-5.2

如何在visual studio 2010中编译链接器的文件。

以下是使用Visual Studio 2010的Lua 5.2.1源代码的步骤:

  1. cl / MD / O2 / c / DLUA_BUILD_AS_DLL * .c
  2. 使用扩展名“.o”重命名“lua.obj”和“luac.obj”。他们将不会被选中
  3. link / DLL /IMPLIB:lua5.2.lib /OUT:lua5.2.dll * .obj
  4. link /OUT:lua.exe lua.o lua5.2.lib
  5. lib /OUT:lua5.2-static.lib * .obj
  6. link /OUT:luac.exe luac.o lua5.2-static.lib
  7. 从上述所有步骤中,我选择lua5.2.lib并将其添加到链接器,如下所示:

    enter image description here

    当我使用Dev-C ++编译以下C代码时,它没有给出任何错误,但是当我用Lua用require命令调用它时,它说它无法找到它。

    #include<windows.h>
    #include<math.h>
    #include "lauxlib.h"
    #include "lua.h"
    
    
    #define LUA_LIB   int __declspec(dllexport)
    
    
    
    static int IdentityMatrix(lua_State *L)
    {
        int in = lua_gettop(L);
        if (in!=1)
        {
           lua_pushstring(L,"Maximum 1 argument");
           lua_error(L);
        }
        lua_Number n = lua_tonumber(L,1);
        lua_newtable(L);                  /*                 tabOUT n */
        int i,j;
        for (i=1;i<=n;i++)
        {
            lua_newtable(L);              /*         row(i) tabOUT n */
            lua_pushnumber(L,i);          /*       i row(i) tabOUT n */
            for (j=1;j<=n;j++)
            {
                lua_pushnumber(L,j);      /*     j i row(i) tabOUT n */
                if (j==i)
                {
                    lua_pushnumber(L,1);
                }
                else                      /* 0/1 j i row(i) tabOUT n */
                {
                    lua_pushnumber(L,0);
                }
                /*  Put 0/1 inside row(i) at j position */
                lua_settable(L,-4);       /*       i row(i) tabOUT n */
            }
            lua_insert(L,-2);             /*       row(i) i tabOUT n */
            lua_settable(L,2);            /*                tabOUT n */
        }
        return 1;
    }
    
    
    static const struct luaL_Reg LuaMath [] = {{"IdentityMatrix", IdentityMatrix},
                                               {            NULL,           NULL}};
    
    LUA_LIB luaopen_LuaMath(lua_State *L)
    {
        luaL_newlib(L,LuaMath);
        return 1;
    }
    

    当我运行这个简单的Lua代码时:

    require("LuaMath")
    
    A=LuaMath.IdentityMatrix(4)
    

    错误写入

    error loading module 'LuaMath' from file './LuaMath.dll': impossible to find the specified module'.
    

    任何帮助?

0 个答案:

没有答案
相关问题