From f41130bafe254e9a7a2a6616b4cc9852019c9513 Mon Sep 17 00:00:00 2001 From: halx99 Date: Tue, 21 Jun 2016 14:31:25 +0800 Subject: [PATCH] luabindings: Add script with utf-8 bom support. --- cocos/scripting/lua-bindings/manual/CCLuaStack.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cocos/scripting/lua-bindings/manual/CCLuaStack.cpp b/cocos/scripting/lua-bindings/manual/CCLuaStack.cpp index be53250526..bb0bf2ce13 100644 --- a/cocos/scripting/lua-bindings/manual/CCLuaStack.cpp +++ b/cocos/scripting/lua-bindings/manual/CCLuaStack.cpp @@ -862,6 +862,14 @@ int LuaStack::luaLoadBuffer(lua_State *L, const char *chunk, int chunkSize, cons } else { + // UTF-8 BOM? skip + if (static_cast(chunk[0]) == 0xEF && + static_cast(chunk[1]) == 0xBB && + static_cast(chunk[2]) == 0xBF) + { + chunk += 3; + chunkSize -= 3; + } r = luaL_loadbuffer(L, chunk, chunkSize, chunkName); }