【发布时间】:2014-06-02 00:07:47
【问题描述】:
我正在使用 LuaJ 将不同的 Lua 脚本加载到 Java 中的全局环境中,如下所示:
globals = JmePlatform.standardGlobals();
LuaValue chunk = globals.load(new FileInputStream(luaScriptA), scriptName, "t", globals);
chunk.call();
我的问题是,例如,如果 scriptName 恰好是 require、print、error、math 或调用后全局变量中已经存在的任何其他名称
globals = JmePlatform.standardGlobals();
,该脚本实际上将替换/覆盖打印等实际功能。
有什么简单的方法可以防止这种情况发生吗?
不幸的是一个测试,例如:
if (globals.get(scriptName) != Globals.NIL) {
//then dont allow script load
}
对我不起作用,因为在某些情况下,当脚本更新时,它实际上应该覆盖现有脚本。
【问题讨论】: