在脚本中需要LUA模块,称为C
Require Lua Module In Script Called from C++
我正在使用LUA5.1的C 应用程序中使用VS2015。我正在运行一个非常简单的LUA脚本,没有问题,RAW LUA工作正常。但是,当我尝试导入LUA模块" socket.http"时,我的应用程序不喜欢它,因为我认为它找不到该模块。
我的问题是如何允许我的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("-- %sn", 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 '.sockethttp.lua'
no file 'C:UsersgeorgDesktopgitARGOGameATracknophiliaDebugluasockethttp.lua'
no file 'C:UsersgeorgDesktopgitARGOGameATracknophiliaDebugluasockethttpinit.lua'
no file 'C:UsersgeorgDesktopgitARGOGameATracknophiliaDebugsockethttp.lua'
no file 'C:UsersgeorgDesktopgitARGOGameATracknophiliaDebugsockethttpinit.lua'
no file 'C:Program Files (x86)Lua5.1luasockethttp.luac'
no file '.sockethttp.dll'
no file '.sockethttp51.dll'
no file 'C:UsersgeorgDesktopgitARGOGameATracknophiliaDebugsockethttp.dll'
no file 'C:UsersgeorgDesktopgitARGOGameATracknophiliaDebugsockethttp51.dll'
no file 'C:UsersgeorgDesktopgitARGOGameATracknophiliaDebugclibssockethttp.dll'
no file 'C:UsersgeorgDesktopgitARGOGameATracknophiliaDebugclibssockethttp51.dll'
no file 'C:UsersgeorgDesktopgitARGOGameATracknophiliaDebugloadall.dll'
no file 'C:UsersgeorgDesktopgitARGOGameATracknophiliaDebugclibsloadall.dll'
no file '.socket.dll'
no file '.socket51.dll'
no file 'C:UsersgeorgDesktopgitARGOGameATracknophiliaDebugsocket.dll'
no file 'C:UsersgeorgDesktopgitARGOGameATracknophiliaDebugsocket51.dll'
no file 'C:UsersgeorgDesktopgitARGOGameATracknophiliaDebugclibssocket.dll'
no file 'C:UsersgeorgDesktopgitARGOGameATracknophiliaDebugclibssocket51.dll'
no file 'C:UsersgeorgDesktopgitARGOGameATracknophiliaDebugloadall.dll'
no file 'C:UsersgeorgDesktopgitARGOGameATracknophiliaDebugclibsloadall.dll'
模块的规则是相同的,无论您是从C 启动的脚本还是从LUA命令行解释器。
您必须在LUA搜索器/加载程序尝试找到它的路径中拥有该模块。请参阅所搜索的路径列表,放置在一个搜索路径中,HTTP DLL(以Lua静态链接为lua,以与您的项目相同的设置进行了编译)。而且您必须与程序一起分发该模块,不要指望它安装在用户的PC上。
相关文章:
- 尝试导入pybind-opencv模块时出现libgtk错误
- 为什么当我解模块化时,这个C++代代码"效率较低"?
- 如果C++对象的类在另一个boost模块中声明,如何使用boost将指向该对象的指针返回到python
- 内联如何影响模块接口中的成员函数
- C++返回 Numpy 数组的 Python 扩展模块
- 当我尝试加载内核模块时,如何修复C++中的这个 malloc() 错误?
- 如何从线程中的不同模块调用函数?
- 如何使用 soong 命名空间来有条件地编译模块
- asn1c 不会从 asn.1 模块中提取八位字节字符串的默认值
- CMake - 模块 + 库混淆
- 特征 LLT 模块给出不正确的结果?
- 枚举进程模块在有效句柄上返回无效句柄
- 在 python 模块中导入子模块时PyImport_Import失败
- 将 PCL 链接到 Cython C++ 模块
- 即使直接从官方示例中复制,也找不到未知类型名称QML_ELEMENT和 QML 模块
- 电源功能模块化操作
- 聚合初始化和删除的复制构造函数,也称为不可复制的 obejcts 作为字段
- 如何告诉本机节点模块所需的dll存储在哪里?
- 如何为模块化应用程序实现C++插件系统
- 在脚本中需要LUA模块,称为C