Skip to content

Commit

Permalink
增加StringHash函数
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed Sep 17, 2013
1 parent bddc6cb commit 9a49665
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Development/Editor/Core/Script/Lua/compile/template.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion Development/Editor/Plugin/Lua/ar_storm/luaopen_ar_storm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<LPCSTR>(gOrdinalStorm##name##));

Expand All @@ -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)
}
}

Expand Down Expand Up @@ -170,6 +173,11 @@ namespace NLuaAPI { namespace NSTORM {
luabind::object(pState, false).push(pState);
}
}

uint32_t LuaStormStringHash(const char* str)
{
return aero::std_call<uint32_t>(pgStormSStrHash, str);
}
}}

int luaopen_ar_storm(lua_State *pState)
Expand All @@ -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)
]
];

Expand Down

0 comments on commit 9a49665

Please sign in to comment.