我如何在iOS应用程序中使用LuaSocket?
2015-2-7 13:19:52
收藏:0
阅读:71
评论:1
我正在开发一款 iOS 应用,可以运行 Lua 脚本,我可以通过 CocoaPods 轻松集成基本的 lua 支持,但是如何将 LuaSocket 库添加到其中呢? LuaSocket 包含一些 C 和一些 Lua 文件,有没有人有什么想法呢?谢谢!
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- 如何将两个不同的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 代码?
- addEventListener 返回 nil Lua
- Lua中获取用户配置主目录的跨平台方法
我使用了LuaSocket 2.0.2版本和Lua 5.1版本。修改了一些文件之后[未知类型名称“luaL_reg”;你是不是想说“luaL_Reg”?],我成功编译了。还移除了wsocket(.h和.c)文件。所以现在系统正在编译。经过一些搜索,我发现Cocos2d-x源代码(3.0.4)使用了luasocket文件夹(并有liblua.a)。我又一次移除了wsocket文件,然后成功地编译了。我用了以下代码:
-(void)addBundlePathToLuaState:(lua_State*)L { lua_getglobal(L, "package"); lua_getfield(L, -1, "path"); // get field "path" from table at top of stack (-1) const char* current_path_const = lua_tostring(L, -1); // grab path string from top of stack NSString* current_path = [NSString stringWithFormat:@"%s;%@/?.lua", current_path_const, [[NSBundle mainBundle]resourcePath]]; lua_pop(L, 1); // get rid of the string on the stack we just pushed on line 5 lua_pushstring(L, [current_path UTF8String]); // push the new one NSLog(@"path current %s", [current_path UTF8String]); lua_setfield(L, -2, "path"); // set the field "path" in table at -2 with value at top of stack lua_pop(L, 1); // get rid of package table from top of stack }和
int status; lua_State *La; La = luaL_newstate(); NSBundle* myBundle = [NSBundle mainBundle]; NSString* myImage = [myBundle pathForResource:@"a" ofType:@"lua"]; const char *stringAsChar = [myImage cStringUsingEncoding:[NSString defaultCStringEncoding]]; NSLog(@"mypath %s", stringAsChar); luaL_openlibs(La); /* Load Lua libraries */ /* Load the file containing the script we are going to run */ status = luaL_loadfile(La, stringAsChar); NSString *luaFilePath = [[NSBundle mainBundle] pathForResource:@"a" ofType:@"lua"]; [self addBundlePathToLuaState:La];我的脚本使用了local socket = require("socket")但是问题是它找不到核心socket.lua:13:module 'socket.core' not found,no field package.preload['socket.core']。所以我认为你不能很快成功 :)