15

ZeroBrane Studio 简易适配 Lua 5.4

 3 years ago
source link: https://blog.csdn.net/tkokof1/article/details/106531843
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

ZeroBrane Studio 简易适配 Lua 5.4

本文介绍了 ZeroBrane Studio 简易适配 Lua 5.4 的一些细节

Lua 5.4 已经到 rc4 版本了(更新: 目前 Lua 5.4 已经正式发布了~),相信不少朋友都已经有所尝试,最简单的测试方法应该就是手动编译一个 lua.exe,然后直接命令行执行脚本:

lua.exe lua_script_path

当然,使用 IDE 来编写测试脚本会更方便些,自己平时用 ZeroBrane Studio 比较多,不过最新版本的 ZeroBrane Studio 还没有直接支持 Lua 5.4 脚本的运行和调试,自己简单尝试适配了一下,发现还是比较简单的:

  • 首先,我们进入 ZeroBrane Studio 的程序目录,在 interpreters 文件夹下新建 luadeb54.lua 脚本,内容如下:
dofile 'interpreters/luabase.lua'
local interpreter = MakeLuaInterpreter(5.4, ' 5.4')
interpreter.skipcompile = true
return interpreter
在这里插入图片描述
  • 接着,我们将我们编译的 lua.exe 更名为 lua54.exe, 并拷贝至 bin 文件夹下:
在这里插入图片描述

经过上面两步,我们就已经可以在 ZeroBrane Studio 运行 Lua 5.4 脚本了,不过仍然不能调试,所以:

  • 最后,我们再使用 Lua 5.4 编译一下 luasocket,将生成的(两个) dll 文件(分别置于 mime 和 socket 文件夹下)拷贝至新建文件夹 clibs54(bin 目录下) 中
在这里插入图片描述
在这里插入图片描述

至此,我们就可以在 ZeroBrane Studio 中进行基本的(Lua 5.4)脚本运行和调试了:

在这里插入图片描述

简单写个测试脚本:

print("test begin")

local tbcmt = { __close = function() print("close to-be-closed var") end }

local function create_tbcv()
    local tbcv = {}
    setmetatable(tbcv, tbcmt)
    return tbcv
end
    
do
    local tbcv <close> = create_tbcv()
end

print("test end")

在 ZeroBrane Studio 中运行并得到输出:

在这里插入图片描述

如果需要调试也是可以的:

在这里插入图片描述
  • 文中介绍的适配方式比较简易,仅适用于较简单的开发场景
  • 对于关键字标准库等的适配没有处理,有兴趣的朋友可以尝试调整 api/lua/baselib.lua 文件

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK