mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Script: Reverted Unicode change (99c67f7
)
This commit is contained in:
@ -61,15 +61,27 @@ void LuaManager::ReportErrors(lua_State* L)
|
||||
const char* error = lua_tostring(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
const char* pos = error + 4; // Skip the drive
|
||||
|
||||
// Get rid of everything up to the filename
|
||||
while (*pos != ':')
|
||||
{
|
||||
if (*pos == '\\')
|
||||
{
|
||||
error = pos + 1;
|
||||
}
|
||||
++pos;
|
||||
}
|
||||
|
||||
LogWithArgs(LOG_ERROR, L"Script: %S", error);
|
||||
}
|
||||
|
||||
void LuaManager::PushWide(lua_State* L, const WCHAR* str)
|
||||
{
|
||||
lua_pushstring(L, ConvertToUTF8(str).c_str());
|
||||
lua_pushstring(L, ConvertToAscii(str).c_str());
|
||||
}
|
||||
|
||||
std::wstring LuaManager::ToWide(lua_State* L, int narg)
|
||||
{
|
||||
return ConvertUTF8ToWide(lua_tostring(L, narg));
|
||||
return ConvertToWide(lua_tostring(L, narg));
|
||||
}
|
||||
|
@ -25,62 +25,15 @@
|
||||
** The constructor
|
||||
**
|
||||
*/
|
||||
LuaScript::LuaScript(const WCHAR* scriptFile) :
|
||||
LuaScript::LuaScript(const char* file) :
|
||||
m_Ref(LUA_NOREF),
|
||||
m_Initialized(false)
|
||||
m_Initialized(true)
|
||||
{
|
||||
lua_State* L = LuaManager::GetState();
|
||||
int result = luaL_loadfile(L, file);
|
||||
|
||||
FILE* file = _wfopen(scriptFile, L"rb");
|
||||
if (!file)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
fseek(file, 0, SEEK_END);
|
||||
long fileSize = ftell(file);
|
||||
if (fileSize < 3)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int load = 0;
|
||||
std::string scriptName = ConvertToUTF8(wcsrchr(scriptFile, L'\\') + 1);
|
||||
const char* scriptNameSz = scriptName.c_str();
|
||||
|
||||
BYTE* fileData = new BYTE[fileSize];
|
||||
fseek(file, 0, SEEK_SET);
|
||||
fread(fileData, fileSize, 1, file);
|
||||
|
||||
if (fileData[0] == 0xEF && fileData[1] == 0xBB && fileData[2] == 0xBF)
|
||||
{
|
||||
// Has UTF8 BOM, so assume that data is already in UTF8.
|
||||
const char* utf8Data = (char*)fileData + 3;
|
||||
int utf8Size = fileSize - 3;
|
||||
|
||||
load = luaL_loadbuffer(L, utf8Data, utf8Size, scriptNameSz);
|
||||
delete [] fileData;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Convert the file contents first to WCHAR with respect to the current
|
||||
// code page and then to UTF8 in order to preserve code page specific chars.
|
||||
|
||||
int wideSize = MultiByteToWideChar(CP_ACP, 0, (char*)fileData, fileSize, NULL, 0);
|
||||
WCHAR* wideData = new WCHAR[wideSize];
|
||||
MultiByteToWideChar(CP_ACP, 0, (char*)fileData, fileSize, wideData, wideSize);
|
||||
delete [] fileData;
|
||||
|
||||
int utf8Size = WideCharToMultiByte(CP_UTF8, 0, wideData, wideSize, NULL, 0, NULL, NULL);
|
||||
char* utf8Data = new char[utf8Size];
|
||||
WideCharToMultiByte(CP_UTF8, 0, wideData, wideSize, utf8Data, utf8Size, NULL, NULL);
|
||||
delete [] wideData;
|
||||
|
||||
load = luaL_loadbuffer(L, utf8Data, utf8Size, scriptNameSz);
|
||||
delete [] utf8Data;
|
||||
}
|
||||
|
||||
if (load == 0)
|
||||
// If the file loaded okay.
|
||||
if (result == 0)
|
||||
{
|
||||
// Create the table this script will reside in
|
||||
lua_newtable(L);
|
||||
@ -107,12 +60,11 @@ LuaScript::LuaScript(const WCHAR* scriptFile) :
|
||||
lua_setfenv(L, -2);
|
||||
|
||||
// Execute the Lua script
|
||||
if (lua_pcall(L, 0, 0, 0) == 0)
|
||||
{
|
||||
m_Initialized = true;
|
||||
}
|
||||
else
|
||||
result = lua_pcall(L, 0, 0, 0);
|
||||
|
||||
if (result)
|
||||
{
|
||||
m_Initialized = false;
|
||||
LuaManager::ReportErrors(L);
|
||||
|
||||
luaL_unref(L, LUA_GLOBALSINDEX, m_Ref);
|
||||
@ -121,10 +73,9 @@ LuaScript::LuaScript(const WCHAR* scriptFile) :
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Initialized = false;
|
||||
LuaManager::ReportErrors(L);
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -223,7 +174,7 @@ int LuaScript::RunFunctionWithReturn(const char* funcName, double& numValue, std
|
||||
else if (type == LUA_TSTRING)
|
||||
{
|
||||
const char* str = lua_tostring(L, -1);
|
||||
strValue = ConvertUTF8ToWide(str);
|
||||
strValue = ConvertToWide(str);
|
||||
numValue = strtod(str, NULL);
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
class LuaScript
|
||||
{
|
||||
public:
|
||||
LuaScript(const WCHAR* scriptFile);
|
||||
LuaScript(const char* file);
|
||||
~LuaScript();
|
||||
|
||||
bool IsInitialized() { return m_Initialized; }
|
||||
|
@ -53,7 +53,7 @@ static int Print(lua_State* L)
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
Log(LOG_DEBUG, ConvertUTF8ToWide(message.c_str()).c_str());
|
||||
Log(LOG_DEBUG, ConvertToWide(message.c_str()).c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user