LuaManager::RunScript -> LuaHelpers::RunScript.
(Functions in LuaManager can accidentally bypass locking semantics, so they should be kept to a minimum.)
This commit is contained in:
@@ -91,7 +91,7 @@ void ActorCommands::Register()
|
|||||||
Lua *L = LUA->Get();
|
Lua *L = LUA->Get();
|
||||||
|
|
||||||
CString sError;
|
CString sError;
|
||||||
if( !LUA->RunScript( m_sLuaFunction, "in", sError, 1 ) )
|
if( !LuaHelpers::RunScript( L, m_sLuaFunction, "in", sError, 1 ) )
|
||||||
{
|
{
|
||||||
FAIL_M( ssprintf("Compiling \"%s\": %s", m_sLuaFunction.c_str(), sError.c_str()) );
|
FAIL_M( ssprintf("Compiling \"%s\": %s", m_sLuaFunction.c_str(), sError.c_str()) );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -248,7 +248,7 @@ bool LuaManager::RunScriptFile( const CString &sFile )
|
|||||||
}
|
}
|
||||||
|
|
||||||
CString sError;
|
CString sError;
|
||||||
if( !RunScript( sScript, sFile, sError, 0 ) )
|
if( !LuaHelpers::RunScript( L, sScript, sFile, sError, 0 ) )
|
||||||
{
|
{
|
||||||
sError = ssprintf( "Lua runtime error: %s", sError.c_str() );
|
sError = ssprintf( "Lua runtime error: %s", sError.c_str() );
|
||||||
Dialog::OK( sError, "LUA_ERROR" );
|
Dialog::OK( sError, "LUA_ERROR" );
|
||||||
@@ -258,7 +258,7 @@ bool LuaManager::RunScriptFile( const CString &sFile )
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LuaManager::RunScript( const CString &sScript, const CString &sName, CString &sError, int iReturnValues )
|
bool LuaHelpers::RunScript( Lua *L, const CString &sScript, const CString &sName, CString &sError, int iReturnValues )
|
||||||
{
|
{
|
||||||
// load string
|
// load string
|
||||||
{
|
{
|
||||||
@@ -290,7 +290,7 @@ bool LuaManager::RunScript( const CString &sScript, const CString &sName, CStrin
|
|||||||
bool LuaManager::RunScript( const CString &sExpression, const CString &sName, int iReturnValues )
|
bool LuaManager::RunScript( const CString &sExpression, const CString &sName, int iReturnValues )
|
||||||
{
|
{
|
||||||
CString sError;
|
CString sError;
|
||||||
if( !RunScript( sExpression, sName.size()? sName:CString("in"), sError, iReturnValues ) )
|
if( !LuaHelpers::RunScript( L, sExpression, sName.size()? sName:CString("in"), sError, iReturnValues ) )
|
||||||
{
|
{
|
||||||
sError = ssprintf( "Lua runtime error parsing \"%s\": %s", sName.size()? sName.c_str():sExpression.c_str(), sError.c_str() );
|
sError = ssprintf( "Lua runtime error parsing \"%s\": %s", sName.size()? sName.c_str():sExpression.c_str(), sError.c_str() );
|
||||||
Dialog::OK( sError, "LUA_ERROR" );
|
Dialog::OK( sError, "LUA_ERROR" );
|
||||||
|
|||||||
@@ -61,10 +61,6 @@ public:
|
|||||||
/* Reset the environment, freeing any globals left over by previously executed scripts. */
|
/* Reset the environment, freeing any globals left over by previously executed scripts. */
|
||||||
void ResetState();
|
void ResetState();
|
||||||
|
|
||||||
/* Run a script with the given name. Return values are left on the Lua stack.
|
|
||||||
* Returns false on error, with sError set*/
|
|
||||||
bool RunScript( const CString &sScript, const CString &sName, CString &sError, int iReturnValues = 0 );
|
|
||||||
|
|
||||||
/* Convenience: run a script with one return value, displaying an error on failure.
|
/* Convenience: run a script with one return value, displaying an error on failure.
|
||||||
* The return value is left on the Lua stack. */
|
* The return value is left on the Lua stack. */
|
||||||
bool RunScript( const CString &sExpression, const CString &sName = "", int iReturnValues = 0 );
|
bool RunScript( const CString &sExpression, const CString &sName = "", int iReturnValues = 0 );
|
||||||
@@ -97,6 +93,10 @@ private:
|
|||||||
|
|
||||||
namespace LuaHelpers
|
namespace LuaHelpers
|
||||||
{
|
{
|
||||||
|
/* Run a script with the given name. Return values are left on the Lua stack.
|
||||||
|
* Returns false on error, with sError set. */
|
||||||
|
bool RunScript( Lua *L, const CString &sScript, const CString &sName, CString &sError, int iReturnValues = 0 );
|
||||||
|
|
||||||
/* Create a Lua array (a table with indices starting at 1) of the given vector,
|
/* Create a Lua array (a table with indices starting at 1) of the given vector,
|
||||||
* and push it on the stack. */
|
* and push it on the stack. */
|
||||||
void CreateTableFromArrayB( Lua *L, const vector<bool> &aIn );
|
void CreateTableFromArrayB( Lua *L, const vector<bool> &aIn );
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ void LuaData::LoadFromString( const CString &s )
|
|||||||
|
|
||||||
/* Restore the serialized data by evaluating it. */
|
/* Restore the serialized data by evaluating it. */
|
||||||
CString sError;
|
CString sError;
|
||||||
if( !LUA->RunScript( s, "serialization", sError, 1 ) )
|
if( !LuaHelpers::RunScript( L, s, "serialization", sError, 1 ) )
|
||||||
{
|
{
|
||||||
/* Serialize() should never return an invalid script. Drop the failed
|
/* Serialize() should never return an invalid script. Drop the failed
|
||||||
* script into the log (it may be too big to pass to FAIL_M) and fail. */
|
* script into the log (it may be too big to pass to FAIL_M) and fail. */
|
||||||
|
|||||||
Reference in New Issue
Block a user