c++ - 如何通过 C++ 全局加载 file.lua 库而无需使用:loadfile("file.lua")() 导入它?
问题描述
我在这个 github 上找到了一个名为“json.lua”的库:github json.lua
我通过 main.lua 文件导入这个库,如下所示:
local json = loadfile("json.lua")() -- json = library loaded
print("json decoded : "..json.decode("13E+2")) -- will print : json decoded = 1300.0
但是我想全局使用“ json ”变量,而不必使用以下命令导入它: loadfile("json.lua")()
有没有办法将json.lua 或 json.lua 文件字符串 直接全局加载到 lua VM 中,以便任何其他文件( main1.lua、main2.lua、main3.lua、...lua )我只需键入“json.lua”。 ANY_FUNCTION "然后去上班吗?
解决方案
在加载脚本之前在 C++ 中运行它:
luaL_dostring(L,"json = dofile('json.lua')");
推荐阅读
- python - 无法使用 python 从 sftp 服务器下载文件
- excel - 如何将单元格值定义为工作表
- c# - C# 或 SQL 中的隔离级别 - 将使用哪一个?
- python - 文本 = sio.getvalue() ; 在“For”循环中返回“文本”无法识别
- angular - Angular @Optional 指令注入被忽略
- python - 检查列表的元素是否是同一列表中其他列表元素的子元素
- reactjs - 由于 Firebase 身份验证流程导致的循环依赖
- spring - Spring Boot REST 部署:我们需要 TomCat 吗?
- java - gitignore 文件不隐藏 github 的 .idea 目录
- python - Django,“django.contrib.auth.views”没有属性“登录”