diff --git a/Development/Editor/Core/Script/Lua/compile/template.lua b/Development/Editor/Core/Script/Lua/compile/template.lua index c723fbeff..bc739167e 100644 --- a/Development/Editor/Core/Script/Lua/compile/template.lua +++ b/Development/Editor/Core/Script/Lua/compile/template.lua @@ -65,6 +65,10 @@ local function map_file_import(filename) end end +local function string_hash(str) + return string.format('0x%08X', ar.storm.string_hash(str)) +end + template = {} function template.do_compile (self, code, env) @@ -95,7 +99,7 @@ function template.compile(self, map_path, map_handle, map_script_path) package.loaded['slk'] = nil __map_handle__ = map_handle - local env = setmetatable({import = map_file_import}, {__index = _G}) + local env = setmetatable({import = map_file_import, StringHash = string_hash}, {__index = _G}) local success, content = self:do_compile(content, env) if not success then if content then diff --git a/Development/Editor/Plugin/Lua/ar_storm/luaopen_ar_storm.cpp b/Development/Editor/Plugin/Lua/ar_storm/luaopen_ar_storm.cpp index 63766d99c..b8ab3b7fb 100644 --- a/Development/Editor/Plugin/Lua/ar_storm/luaopen_ar_storm.cpp +++ b/Development/Editor/Plugin/Lua/ar_storm/luaopen_ar_storm.cpp @@ -22,6 +22,7 @@ namespace NLuaAPI { namespace NSTORM { const int gOrdinalStormSFileLoadFile = 279; const int gOrdinalStormSFileUnloadFile = 280; const int gOrdinalStormSFileExists = 288; + const int gOrdinalStormSStrHash = 590; void *pgStormSFileOpenArchive; void *pgStormSFileCloseArchive; @@ -33,6 +34,7 @@ namespace NLuaAPI { namespace NSTORM { void *pgStormSFileLoadFile; void *pgStormSFileUnloadFile; void *pgStormSFileExists; + void *pgStormSStrHash; #define INITIALIZE_STORM_FUNCTION_POINTER(name) pgStorm##name = GetProcAddress(stormDll, reinterpret_cast(gOrdinalStorm##name##)); @@ -51,6 +53,7 @@ namespace NLuaAPI { namespace NSTORM { INITIALIZE_STORM_FUNCTION_POINTER(SFileLoadFile) INITIALIZE_STORM_FUNCTION_POINTER(SFileUnloadFile) INITIALIZE_STORM_FUNCTION_POINTER(SFileExists) + INITIALIZE_STORM_FUNCTION_POINTER(SStrHash) } } @@ -170,6 +173,11 @@ namespace NLuaAPI { namespace NSTORM { luabind::object(pState, false).push(pState); } } + + uint32_t LuaStormStringHash(const char* str) + { + return aero::std_call(pgStormSStrHash, str); + } }} int luaopen_ar_storm(lua_State *pState) @@ -185,7 +193,8 @@ int luaopen_ar_storm(lua_State *pState) def("close_archive", &NLuaAPI::NSTORM::LuaMpqNativeCloseArchive), def("extract_file", &NLuaAPI::NSTORM::LuaMpqNativeExtractFile), def("has_file", &NLuaAPI::NSTORM::LuaMpqNativeHasFile), - def("load_file", &NLuaAPI::NSTORM::LuaMpqNativeLoadFile) + def("load_file", &NLuaAPI::NSTORM::LuaMpqNativeLoadFile), + def("string_hash", &NLuaAPI::NSTORM::LuaStormStringHash) ] ];