lua: 为什么字符“$”导致 "unexpected symbol near $"

lua: why the character "$" cause "unexpected symbol near $"

我是 Lua 的新手。我写了一个脚本,其中有一行

ISH_activation.getState() = CONST_ACTIVATION_STATE$ON

然后,我需要编写另一个 C++ 脚本来从 Lua 读取这一行并解析它。现在的问题是,当我尝试调试 lua 脚本本身时,在这一行它给我错误 "unexpected symbol near '$'"。

我不知道为什么会这样。 Lua 中是否不允许使用类似 "CONST_ACTIVATION_STATE$ON" 的格式?而“$”是Lua中的一个特殊字符,我们不能使用它吗?(但我没有找到任何提到这个的东西)......

好吧,你有没有发现任何说你 可以 使用 $ 的东西? :)

是的,您不能在标识符中使用美元符号。来自 manual:

Names (also called identifiers) in Lua can be any string of letters, digits, and underscores, not beginning with a digit. Identifiers are used to name variables, table fields, and labels.

如果你真的想保留美元符号,你可以改用字符串

"CONST_ACTIVATION_STATE$ON"