在C++中调用Lua脚本时要求Lua模块
2017-3-2 12:29:48
收藏:0
阅读:294
评论:1
我在使用VS2015的C++应用程序中运行Lua5.1的非常简单的Lua脚本,没有问题,原始Lua很好。但是当我尝试导入lua模块“socket.http”时,我的应用程序不喜欢它,因为我想象它找不到模块。
我的问题是如何允许我的Lua脚本(从c++运行)访问像socket.http这样的Lua模块?
我的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")
errors
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'
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- Lua 虚拟机加密load(string.dump(function)) 后执行失败问题如何解决
- 我想创建一个 Nginx 规则,禁止访问
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?

无论您是从 C++ 开始还是从 Lua 命令行解释器开始编写脚本,模块的规则都是相同的。
您必须将该模块放在 Lua 搜寻/加载程序尝试查找它的路径中。查看搜索路径列表,在其中一个搜索路径中放置该 http dll(使用与您的项目相同的设置编译,以防 Lua 静态链接)。
并且您必须将该模块与您的程序一起分发,不要期望它在用户的计算机上安装。