如何通过C ++全局加载file.lua库而不必使用:loadfile("file.lua")()进行导入?

我有一个名为"json.lua"的库,可以在此github上找到:[github json.lua](https://github.com/rxi/json.lua)

我通过main.lua文件导入了这个库,就像这样:

本地json = loadfile"json.lua")() - > json =已加载库
打印(“ json decoded:“ .. json.decode(“ 13E +2”))-将打印:json decoded = 1300.0

但是我想全局使用"json"变量,而不必使用:loadfile("json.lua")()进行导入

是否有任何方式可以将_json.lua_ _json.lua文件字符串_直接全局加载到lua VM中,以便任何其他文件(main1.lua,main2.lua,main3.lua,...lua)只需键入"json.ANY_FUNCTION "并开始工作?

点赞
用户107090
用户107090

在加载脚本之前,在 C++ 中运行以下命令:

luaL_dostring(L,"json = dofile('json.lua')");
2021-06-30 16:24:28