summaryrefslogtreecommitdiff
path: root/src/scripting
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2010-05-29 18:36:20 +0200
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2010-05-29 20:49:40 +0200
commit7d01ae57c61c604ed6078bb3910283d9a8a6ffc7 (patch)
tree6cad89ab129687ccb7e0ecd7f82aba84748ec7df /src/scripting
parent0c56831afead73852958a818d154957930ddbecd (diff)
downloadmanaserv-7d01ae57c61c604ed6078bb3910283d9a8a6ffc7.tar.gz
manaserv-7d01ae57c61c604ed6078bb3910283d9a8a6ffc7.tar.bz2
manaserv-7d01ae57c61c604ed6078bb3910283d9a8a6ffc7.tar.xz
manaserv-7d01ae57c61c604ed6078bb3910283d9a8a6ffc7.zip
Only skip the UTF-8 BOM for Lua scripts
libxml2 should be able to handle files with a BOM fine. Reviewed-by: Bertram
Diffstat (limited to 'src/scripting')
-rw-r--r--src/scripting/lua.cpp2
-rw-r--r--src/scripting/script.cpp15
2 files changed, 13 insertions, 4 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index da47d931..507b348f 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -1628,7 +1628,7 @@ LuaScript::LuaScript():
lua_pop(mState, 2);
// Put some callback functions in the scripting environment.
- static luaL_reg const callbacks[] = {
+ static luaL_Reg const callbacks[] = {
{ "npc_create", &npc_create },
{ "npc_message", &npc_message },
{ "npc_choice", &npc_choice },
diff --git a/src/scripting/script.cpp b/src/scripting/script.cpp
index 01d237f3..fe3c5d8d 100644
--- a/src/scripting/script.cpp
+++ b/src/scripting/script.cpp
@@ -27,6 +27,8 @@
#include <cstdlib>
#include <map>
+#include <string.h>
+
typedef std::map< std::string, Script::Factory > Engines;
static Engines *engines = NULL;
@@ -70,15 +72,22 @@ void Script::update()
execute();
}
+static char *skipPotentialBom(char *text)
+{
+ // Based on the C version of bomstrip
+ const char * const utf8Bom = "\xef\xbb\xbf";
+ const int bomLength = strlen(utf8Bom);
+ return (strncmp(text, utf8Bom, bomLength) == 0) ? text + bomLength : text;
+}
+
bool Script::loadFile(const std::string &name)
{
int size;
- // Note: The file is checked for UTF-8 BOM.
- char *buffer = ResourceManager::loadFile(name, size, true);
+ char *buffer = ResourceManager::loadFile(name, size);
if (buffer)
{
mScriptFile = name;
- load(buffer);
+ load(skipPotentialBom(buffer));
free(buffer);
return true;
} else {