Skip to content

Commit 3ed4224

Browse files
author
nitrocaster
committed
Refactor CScriptEngine::parse_script_namespace function.
1 parent e948ea5 commit 3ed4224

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

src/xrScriptEngine/script_engine.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class XRSCRIPTENGINE_API CScriptEngine
166166
bool process_file(LPCSTR file_name);
167167
bool process_file(LPCSTR file_name, bool reload_modules);
168168
bool function_object(LPCSTR function_to_call, luabind::object &object, int type = LUA_TFUNCTION);
169-
IC void parse_script_namespace(LPCSTR function_to_call, LPSTR name_space, u32 const namespace_size, LPSTR function, u32 const function_size);
169+
IC void parse_script_namespace(const char *name, char *ns, u32 nsSize, char *func, u32 funcSize);
170170
template<typename TResult>
171171
IC bool functor(LPCSTR function_to_call, luabind::functor<TResult> &lua_function);
172172
#ifdef USE_DEBUGGER

src/xrScriptEngine/script_engine_inline.hpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,21 @@ CScriptProcess *CScriptEngine::script_process(const ScriptProcessor &process_id)
2323
return nullptr;
2424
}
2525

26-
IC void CScriptEngine::parse_script_namespace(LPCSTR function_to_call, LPSTR name_space,
27-
u32 const namespace_size, LPSTR function, u32 const function_size)
26+
IC void CScriptEngine::parse_script_namespace(const char *name, char *ns, u32 nsSize, char *func, u32 funcSize)
2827
{
29-
LPCSTR I = function_to_call, J = nullptr;
30-
for (; ; J = I , ++I)
28+
auto p = strrchr(name, '.');
29+
if (!p)
3130
{
32-
I = strchr(I, '.');
33-
if (!I)
34-
break;
31+
xr_strcpy(ns, nsSize, GlobalNamespace);
32+
p = name-1;
3533
}
36-
xr_strcpy(name_space, namespace_size, GlobalNamespace);
37-
if (!J)
38-
xr_strcpy(function, function_size, function_to_call);
3934
else
4035
{
41-
CopyMemory (name_space,function_to_call, u32(J - function_to_call)*sizeof(char)) ;
42-
name_space[u32(J - function_to_call)] = 0;
43-
xr_strcpy(function, function_size, J + 1);
36+
VERIFY(u32(p-name+1)<=nsSize);
37+
strncpy(ns, name, p-name);
38+
ns[p-name] = 0;
4439
}
40+
xr_strcpy(func, funcSize, p+1);
4541
}
4642

4743
template<typename TResult>

0 commit comments

Comments
 (0)