2017-03-02 76 views
0

我在使用Lua5.1的C++应用程序中使用VS2015。我正在运行一个非常简单的Lua脚本,没有问题,原始lua工作正常。但是当我尝试导入一个lua模块“socket.http”时,我的应用程序不喜欢它,因为我想它无法找到该模块。要求在C++脚本中调用Lua模块

我的问题是如何让我的lua脚本(从C++运行)访问lua模块,如socket.http?

我project.cpp

#include "stdafx.h" 
#include <iostream> 

extern "C" 
{ 
#include <../dependancies/lua51/include/lua.h> 
#include <../dependancies/lua51/include/lauxlib.h> 
#include <../dependancies/lua51/include/lualib.h> 
} 

void report_errors(lua_State *L, int status) 
{ 
    if (status != 0) 
    { 
     printf("-- %s\n", lua_tostring(L, -1)); 
     lua_pop(L, 1); // remove error message 
    } 
} 

int main() 
{ 
    // create a Lua state 
    lua_State* L = luaL_newstate(); 

    // load standard libs 
    luaL_openlibs(L); 

    int lscript = luaL_dofile(L, "test1.lua"); 

    report_errors(L, lscript); 

    system("PAUSE"); 
    return 0; 
} 

test1.lua

local http = require("socket.http") 

错误

module 'socket.http' not found: 
    no field package.preload['socket.http'] 
    no file '.\socket\http.lua' 
    no file 'C:\Users\georg\Desktop\git\ARGO\Game\ATracknophilia\Debug\lua\socket\http.lua' 
    no file 'C:\Users\georg\Desktop\git\ARGO\Game\ATracknophilia\Debug\lua\socket\http\init.lua' 
    no file 'C:\Users\georg\Desktop\git\ARGO\Game\ATracknophilia\Debug\socket\http.lua' 
    no file 'C:\Users\georg\Desktop\git\ARGO\Game\ATracknophilia\Debug\socket\http\init.lua' 
    no file 'C:\Program Files (x86)\Lua\5.1\lua\socket\http.luac' 
    no file '.\socket\http.dll' 
    no file '.\socket\http51.dll' 
    no file 'C:\Users\georg\Desktop\git\ARGO\Game\ATracknophilia\Debug\socket\http.dll' 
    no file 'C:\Users\georg\Desktop\git\ARGO\Game\ATracknophilia\Debug\socket\http51.dll' 
    no file 'C:\Users\georg\Desktop\git\ARGO\Game\ATracknophilia\Debug\clibs\socket\http.dll' 
    no file 'C:\Users\georg\Desktop\git\ARGO\Game\ATracknophilia\Debug\clibs\socket\http51.dll' 
    no file 'C:\Users\georg\Desktop\git\ARGO\Game\ATracknophilia\Debug\loadall.dll' 
    no file 'C:\Users\georg\Desktop\git\ARGO\Game\ATracknophilia\Debug\clibs\loadall.dll' 
    no file '.\socket.dll' 
    no file '.\socket51.dll' 
    no file 'C:\Users\georg\Desktop\git\ARGO\Game\ATracknophilia\Debug\socket.dll' 
    no file 'C:\Users\georg\Desktop\git\ARGO\Game\ATracknophilia\Debug\socket51.dll' 
    no file 'C:\Users\georg\Desktop\git\ARGO\Game\ATracknophilia\Debug\clibs\socket.dll' 
    no file 'C:\Users\georg\Desktop\git\ARGO\Game\ATracknophilia\Debug\clibs\socket51.dll' 
    no file 'C:\Users\georg\Desktop\git\ARGO\Game\ATracknophilia\Debug\loadall.dll' 
    no file 'C:\Users\georg\Desktop\git\ARGO\Game\ATracknophilia\Debug\clibs\loadall.dll' 
+1

'socket.http'不是原生的Lua模块,也许你安装了它? – bew

回答

0

规则模块是一样的,不管你有脚本从C++或启动来自Lua命令行解释器。
您必须在Lua搜索器/加载器试图找到它的路径中拥有该模块。查看搜索到的路径列表,将http dll(在您的项目中使用相同的设置进行编译,如果Lua静态链接)搜索到的路径之一。 而且你必须随程序一起分发这个模块,不要期望它被安装在用户的电脑上。