【问题标题】:LUA - Unexpected symbol near '・LUA - '・ 附近的意外符号
【发布时间】:2013-01-16 23:17:00
【问题描述】:

我正在尝试在运行时将Lua 脚本加载到我的项目中。但是,每当我尝试这样做时,在加载文件时都会收到以下错误:

Items\food.lua:1: unexpected symbol near '・

文件本身很简单,但我看不出这是什么原因:

config = {
    itemtype = 2,
    name = "Food",
    basevalue = 1,
    inventorytexture = 0,
    red = 255,
    green = 255,
    blue = 255,
    inventorywidth = 1,
    inventoryheight = 1
}

这是我在C# 中用来运行它的代码,以防与它有关:

// In main initialisation
public void ItemSetup()
{
    itemTemplates.Add(new ItemTemplate("Items\\food.lua"));
}

// constructor for ItemTemplate class
Lua LuaLoader = new Lua();

public ItemTemplate(string filename)
{
    LuaLoader.DoFile(filename); // here is where the error comes up
}

我已尝试更改文件本身的设置,但这些似乎都没有帮助。以下是我对此文件的设置:

Build Action: None
Copy to Output Directory: Copy of newer
Custom Tool: <blank>
Custom Tool Namespace: <blank>
File Name: food.lua
Full Path: [...]\Items\food.lua

【问题讨论】:

  • 看起来它可能是一个字节顺序标记。见这里:stackoverflow.com/questions/295472/… 编辑:更多信息:stackoverflow.com/questions/291455/… 我之前在一些 XML 文件中处理过它,所以如果这是同一个问题,我不会感到惊讶。
  • @ChrisSinclair 看起来情况就是这样——我已经删除了文件并在记事本中重新创建了它,问题就解决了。我在 Visual Studio 中创建了它的第一个版本,看起来 Visual Studio 一开始就离开了它。如果您想将此作为答案,我会在那里接受。
  • 很高兴我能帮上忙。我记得我第一次遇到这些时,很难弄清楚到底发生了什么。

标签: c# lua luainterface


【解决方案1】:

看起来它可能是一个字节顺序标记。请参阅:How do I remove the BOM character from my xml fileXML - Data At Root Level is Invalid

我以前在一些 XML 文件中处理过它,所以如果这是同一个问题,我不会感到惊讶。正如在一些链接问题中所指出的,在您的工作流程中,有一些实用程序可以轻松删除/避免它们。

【讨论】:

  • 非常感谢 - 如果我通过 Visual Studio 创建文件并且再次发生这种情况,我已经准备好 Notepad++。
猜你喜欢
  • 2022-01-16
  • 2020-09-14
  • 2023-03-27
  • 2012-10-23
  • 2022-10-13
  • 2015-09-24
  • 1970-01-01
  • 2023-03-18
  • 2020-02-21
相关资源
最近更新 更多