Skip to content

Commit

Permalink
+ print_stack is exported to global namespace
Browse files Browse the repository at this point in the history
Xottab_DUTY: temporary workaround to get lua log output
  • Loading branch information
avoitishin authored and Xottab-DUTY committed Aug 19, 2017
1 parent 8f694c7 commit 06addea
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/xrGame/HudItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,9 @@ bool CHudItem::isHUDAnimationExist(pcstr anim_name)
else // Third person
if (g_player_hud->motion_length(anim_name, HudSection(), m_current_motion_def) > 100)
return true;
#ifdef DEBUG
Msg("~ [WARNING] ------ Animation [%s] does not exist in [%s]", anim_name, HudSection().c_str());
#endif
return false;
}

Expand Down
6 changes: 5 additions & 1 deletion src/xrGame/WeaponMagazined.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ CWeaponMagazined::~CWeaponMagazined()
void CWeaponMagazined::net_Destroy() { inherited::net_Destroy(); }

//AVO: for custom added sounds check if sound exists
bool CWeaponMagazined::WeaponSoundExist(LPCSTR section, LPCSTR sound_name)
bool CWeaponMagazined::WeaponSoundExist(pcstr section, pcstr sound_name) const
{
pcstr str;
bool sec_exist = process_if_exists_set(section, sound_name, &CInifile::r_string, str, true);
if (sec_exist)
return true;
#ifdef DEBUG
Msg("~ [WARNING] ------ Sound [%s] does not exist in [%s]", sound_name, section);
#endif
return false;
}

Expand All @@ -92,6 +94,8 @@ void CWeaponMagazined::Load(LPCSTR section)
#ifdef NEW_SOUNDS //AVO: custom sounds go here
if (WeaponSoundExist(section, "snd_reload_empty"))
m_sounds.LoadSound(section, "snd_reload_empty", "sndReloadEmpty", true, m_eSoundReloadEmpty);
if (WeaponSoundExist(section, "snd_reload_misfire"))
m_sounds.LoadSound(section, "snd_reload_misfire", "sndReloadMisfire", true, m_eSoundReloadMisfire);
#endif //-NEW_SOUNDS

m_sSndShotCurrent = "sndShot";
Expand Down
3 changes: 2 additions & 1 deletion src/xrGame/WeaponMagazined.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class CWeaponMagazined : public CWeapon
ESoundTypes m_eSoundReload;
#ifdef NEW_SOUNDS //AVO: new sounds go here
ESoundTypes m_eSoundReloadEmpty;
ESoundTypes m_eSoundReloadMisfire;
#endif //-NEW_SOUNDS

bool m_sounds_enabled;
Expand Down Expand Up @@ -176,5 +177,5 @@ class CWeaponMagazined : public CWeapon
u16 parent_id, u16 weapon_id, bool send_hit);

//AVO: for custom added sounds check if sound exists
bool WeaponSoundExist(pcstr section, pcstr sound_name);
bool WeaponSoundExist(pcstr section, pcstr sound_name) const;
};
19 changes: 16 additions & 3 deletions src/xrScriptEngine/ScriptEngineScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

void LuaLog(LPCSTR caMessage)
{
if (!GlobalEnv.ScriptEngine->m_stack_is_ready)
Log(caMessage); // Xottab_DUTY: temporary workaround to get lua log output

#ifndef MASTER_GOLD
GlobalEnv.ScriptEngine->script_log(LuaMessageType::Message, "%s", caMessage);
#endif
Expand All @@ -27,6 +30,9 @@ void LuaLog(LPCSTR caMessage)

void ErrorLog(LPCSTR caMessage)
{
if (!GlobalEnv.ScriptEngine->m_stack_is_ready)
Log(caMessage); // Xottab_DUTY: temporary workaround to get lua error output

GlobalEnv.ScriptEngine->error_log("%s", caMessage);
#ifdef DEBUG
GlobalEnv.ScriptEngine->print_stack();
Expand All @@ -44,6 +50,13 @@ void ErrorLog(LPCSTR caMessage)
#endif
}

//AVO:
void PrintStack()
{
GlobalEnv.ScriptEngine->print_stack();
}
//-AVO

void FlushLogs()
{
#ifdef DEBUG
Expand Down Expand Up @@ -149,8 +162,8 @@ SCRIPT_EXPORT(CScriptEngine, (), {
.def("start", &profile_timer_script::start)
.def("stop", &profile_timer_script::stop)
.def("time", &profile_timer_script::time),
def("log", &LuaLog), def("error_log", &ErrorLog), def("flush", &FlushLogs), def("prefetch", &prefetch_module),
def("verify_if_thread_is_running", &verify_if_thread_is_running), def("editor", &is_editor),
def("log", &LuaLog), def("error_log", &ErrorLog), def("flush", &FlushLogs), def("print_stack", &PrintStack),
def("prefetch", &prefetch_module), def("verify_if_thread_is_running", &verify_if_thread_is_running),
def("bit_and", &bit_and), def("bit_or", &bit_or), def("bit_xor", &bit_xor), def("bit_not", &bit_not),
def("user_name", &user_name)];
def("editor", &is_editor), def("user_name", &user_name)];
});
4 changes: 0 additions & 4 deletions src/xrScriptEngine/script_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ int CScriptEngine::vscript_log(LuaMessageType luaMessageType, LPCSTR caFormat, v
#endif
}

#ifdef DEBUG
void CScriptEngine::print_stack()
{
if (!m_stack_is_ready)
Expand All @@ -276,7 +275,6 @@ void CScriptEngine::print_stack()
}
}
}
#endif

int CScriptEngine::script_log(LuaMessageType message, LPCSTR caFormat, ...)
{
Expand Down Expand Up @@ -643,15 +641,13 @@ void CScriptEngine::print_error(lua_State* L, int iErrorCode)
}
}

#ifdef DEBUG
void CScriptEngine::flush_log()
{
string_path log_file_name;
strconcat(sizeof(log_file_name), log_file_name, Core.ApplicationName, "_", Core.UserName, "_lua.log");
FS.update_path(log_file_name, "$logs$", log_file_name);
m_output.save_to(log_file_name);
}
#endif

int CScriptEngine::error_log(LPCSTR format, ...)
{
Expand Down
10 changes: 4 additions & 6 deletions src/xrScriptEngine/script_engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ class XRSCRIPTENGINE_API CScriptEngine
protected:
CScriptProcessStorage m_script_processes;
int m_stack_level;
#ifdef DEBUG

CMemoryWriter m_output; // for call stack
#endif

#ifdef USE_DEBUGGER
#ifndef USE_LUA_STUDIO
CScriptDebugger* m_scriptDebugger;
Expand All @@ -103,9 +103,7 @@ class XRSCRIPTENGINE_API CScriptEngine
#endif

public:
#ifdef DEBUG
bool m_stack_is_ready;
#endif

private:
static CScriptEngine* GetInstance(lua_State* state);
Expand Down Expand Up @@ -145,10 +143,10 @@ class XRSCRIPTENGINE_API CScriptEngine

public:
static void on_error(lua_State* state);
#ifdef DEBUG

void flush_log();
void print_stack();
#endif

using ExporterFunc = XRay::ScriptExporter::Node::ExporterFunc;
CScriptEngine();
virtual ~CScriptEngine();
Expand Down

0 comments on commit 06addea

Please sign in to comment.