这个程序在终端无法运行但在ZeroBrane中可以

x = 10
io.write("输入要打印的变量名称: ")
index = io.read()
f = loadstring("return " ..  index)
print(f())

以上代码在终端中运行时会产生以下错误,但在ZeroBrane Studio中运行时却不会

main.lua:874: attempt to call a nil value (global 'loadstring')
stack traceback:
    main.lua:874: in main chunk [C]: in ?

这一点很重要,因为我正在使用Emacs编写Lua代码。如何解决这个问题?求帮助。

点赞
用户8621712
用户8621712

你的终端 Lua 版本比 ZeroBrane 中的版本高。

Lua 5.3 移除了 loadstring 函数,现在使用 load 函数代替。

2020-11-29 20:14:01