Skip to content

Commit

Permalink
Merge pull request OpenXRay#165 from ShokerStlk/dev_public
Browse files Browse the repository at this point in the history
Some fixes, mostly related to Lua.
  • Loading branch information
Pavel Kovalenko authored Feb 21, 2017
2 parents 925dbad + e36edf4 commit e2f5ad9
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 803 deletions.
786 changes: 0 additions & 786 deletions res/gamedata/configs/system.ltx

This file was deleted.

4 changes: 2 additions & 2 deletions src/xrGame/ActorCondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,8 @@ void CActorCondition::UpdateTutorialThresholds()
}

if (!b) {
luabind::functor<LPCSTR> fl;
R_ASSERT(ai().script_engine().functor<LPCSTR>(cb_name, fl));
luabind::functor<void> fl;
R_ASSERT(ai().script_engine().functor<void>(cb_name, fl));
fl();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/ActorEffector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ BOOL CAnimatorCamEffector::ProcessCam(SCamEffectorInfo& info)

BOOL CAnimatorCamLerpEffector::ProcessCam(SCamEffectorInfo& info)
{
if (!inherited::inherited::ProcessCam(info)) return FALSE;
if (!CEffectorCam::ProcessCam(info)) return FALSE;

const Fmatrix& m = m_objectAnimator->XFORM();
m_objectAnimator->Update(Device.fTimeDelta);
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/ai/stalker/ai_stalker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ void CAI_Stalker::shedule_Update(u32 DT)
}

START_PROFILE("stalker/schedule_update/inherited")
inherited::inherited::shedule_Update(DT);
CEntityAlive::shedule_Update(DT);
STOP_PROFILE

if (Remote()) {
Expand Down
1 change: 0 additions & 1 deletion src/xrGame/script_game_object_script2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ class_<CScriptGameObject>& script_register_game_object1(class_<CScriptGameObject
.def("set_smart_cover_target_lookout", &CScriptGameObject::set_smart_cover_target_lookout)
.def("set_smart_cover_target_fire", &CScriptGameObject::set_smart_cover_target_fire)
.def("set_smart_cover_target_fire_no_lookout", &CScriptGameObject::set_smart_cover_target_fire_no_lookout)
.def("set_smart_cover_target_idle", &CScriptGameObject::set_smart_cover_target_idle)
.def("set_smart_cover_target_default", &CScriptGameObject::set_smart_cover_target_default)

.def("idle_min_time", (void (CScriptGameObject::*)(float)) & CScriptGameObject::idle_min_time)
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/script_game_object_script3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class_<CScriptGameObject>& script_register_game_object2(class_<CScriptGameObject
.def("base_out_restrictions", &CScriptGameObject::base_out_restrictions)
.def("accessible", &CScriptGameObject::accessible_position)
.def("accessible", &CScriptGameObject::accessible_vertex_id)
.def("accessible_nearest", &CScriptGameObject::accessible_nearest)
.def("accessible_nearest", &CScriptGameObject::accessible_nearest, out_value<3>())

//////////////////////////////////////////////////////////////////////////
.def("enable_attachable_item", &CScriptGameObject::enable_attachable_item)
Expand Down
34 changes: 24 additions & 10 deletions src/xrScriptEngine/script_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,13 +505,12 @@ struct raii_guard : private Noncopyable
{
CScriptEngine* scriptEngine;
int m_error_code;
const char* m_error_description;
const char*& m_error_description;

raii_guard(CScriptEngine* scriptEngine, int error_code, const char* error_description)
raii_guard(CScriptEngine* scriptEngine, int error_code, const char*& error_description)
:m_error_code(error_code), m_error_description(error_description)
{
this->scriptEngine = scriptEngine;
m_error_code = error_code;
m_error_description = error_description;
}

~raii_guard()
Expand All @@ -524,9 +523,9 @@ struct raii_guard : private Noncopyable
#ifdef DEBUG
static const bool break_on_assert = !!strstr(Core.Params, "-break_on_assert");
#else
static const bool break_on_assert = true;
static const bool break_on_assert = true; // xxx: there is no point to set it true\false in Release, since game will crash anyway in most cases due to XRAY_EXCEPTIONS disabled in Release build.
#endif
if (!m_error_code) return;
if (!m_error_code) return; // Check "lua_pcall_failed" before changing this!
if (break_on_assert)
R_ASSERT2(!m_error_code, m_error_description);
else
Expand All @@ -535,7 +534,7 @@ struct raii_guard : private Noncopyable
}
};

bool CScriptEngine::print_output(lua_State* L, LPCSTR caScriptFileName, int errorCode)
bool CScriptEngine::print_output(lua_State* L, LPCSTR caScriptFileName, int errorCode, const char* caErrorText)
{
CScriptEngine* scriptEngine = GetInstance(L);
VERIFY(scriptEngine);
Expand Down Expand Up @@ -564,6 +563,12 @@ bool CScriptEngine::print_output(lua_State* L, LPCSTR caScriptFileName, int erro
}
#endif
}

if (caErrorText != NULL)
{
S = caErrorText;
}

return true;
}

Expand Down Expand Up @@ -754,8 +759,18 @@ void CScriptEngine::lua_error(lua_State* L)

int CScriptEngine::lua_pcall_failed(lua_State* L)
{
print_output(L, "", LUA_ERRRUN);
const char* sErrorText = NULL;

#ifndef DEBUG // Debug already do it
const char* lua_error_text = lua_tostring(L, -1); // lua-error text
luaL_traceback(L, L, make_string("[LUA][Error]: %s\n", lua_error_text).c_str(), 1); // add lua traceback to it
sErrorText = lua_tostring(L, -1); // get combined error text from lua stack
lua_pop(L, 1); // restore lua stack
#endif

print_output(L, "", LUA_ERRRUN, sErrorText);
on_error(L);

#if !XRAY_EXCEPTIONS
xrDebug::Fatal(DEBUG_INFO, "LUA error: %s", lua_isstring(L, -1) ? lua_tostring(L, -1) : "");
#endif
Expand Down Expand Up @@ -786,9 +801,8 @@ void CScriptEngine::setup_callbacks()
#if !XRAY_EXCEPTIONS
luabind::set_error_callback(CScriptEngine::lua_error);
#endif
#ifndef MASTER_GOLD

luabind::set_pcall_callback([](lua_State* L) { lua_pushcfunction(L, CScriptEngine::lua_pcall_failed); });
#endif
}
#if !XRAY_EXCEPTIONS
luabind::set_cast_failed_callback(CScriptEngine::lua_cast_failed);
Expand Down
2 changes: 1 addition & 1 deletion src/xrScriptEngine/script_engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class XRSCRIPTENGINE_API CScriptEngine
luabind::object name_space(LPCSTR namespace_name);
int error_log(LPCSTR caFormat, ...);
int script_log(LuaMessageType message, LPCSTR caFormat, ...);
static bool print_output(lua_State* L, LPCSTR caScriptName, int iErrorCode = 0);
static bool print_output(lua_State* L, LPCSTR caScriptName, int iErrorCode = 0, const char* caErrorText = NULL);

private:
static void print_error(lua_State* L, int iErrorCode);
Expand Down

0 comments on commit e2f5ad9

Please sign in to comment.