allow passing params to RunScript

This commit is contained in:
Glenn Maynard
2006-10-15 01:14:32 +00:00
parent fbd0863d56
commit 71af20fdf8
2 changed files with 8 additions and 5 deletions
+7 -4
View File
@@ -459,7 +459,7 @@ bool LuaHelpers::RunScriptFile( const RString &sFile )
}
bool LuaHelpers::RunScript( Lua *L, const RString &sScript, const RString &sName, RString &sError, int iReturnValues )
bool LuaHelpers::RunScript( Lua *L, const RString &sScript, const RString &sName, RString &sError, int iArgs, int iReturnValues )
{
// load string
{
@@ -473,9 +473,12 @@ bool LuaHelpers::RunScript( Lua *L, const RString &sScript, const RString &sName
}
}
// move the function above the params
lua_insert( L, lua_gettop(L) - iArgs );
// evaluate
{
int ret = lua_pcall( L, 0, iReturnValues, 0 );
int ret = lua_pcall( L, iArgs, iReturnValues, 0 );
if( ret )
{
LuaHelpers::Pop( L, sError );
@@ -491,7 +494,7 @@ bool LuaHelpers::RunScript( Lua *L, const RString &sScript, const RString &sName
bool LuaHelpers::RunExpression( Lua *L, const RString &sExpression, const RString &sName )
{
RString sError;
if( !LuaHelpers::RunScript(L, "return " + sExpression, sName.empty()? RString("in"):sName, sError, 1) )
if( !LuaHelpers::RunScript(L, "return " + sExpression, sName.empty()? RString("in"):sName, sError, 0, 1) )
{
sError = ssprintf( "Lua runtime error parsing \"%s\": %s", sName.size()? sName.c_str():sExpression.c_str(), sError.c_str() );
Dialog::OK( sError, "LUA_ERROR" );
@@ -627,7 +630,7 @@ void LuaHelpers::ParseCommandList( Lua *L, const RString &sCommands, const RStri
}
RString sError;
if( !LuaHelpers::RunScript( L, sLuaFunction, sName, sError, 1 ) )
if( !LuaHelpers::RunScript(L, sLuaFunction, sName, sError, 0, 1) )
LOG->Warn( "Compiling \"%s\": %s", sLuaFunction.c_str(), sError.c_str() );
/* The function is now on the stack. */
+1 -1
View File
@@ -49,7 +49,7 @@ namespace LuaHelpers
/* Run a script with the given name. The given number of return values are left on
* the Lua stack. On error, nils are left on the stack, sError is set and
* false is returned. */
bool RunScript( Lua *L, const RString &sScript, const RString &sName, RString &sError, int iReturnValues = 0 );
bool RunScript( Lua *L, const RString &sScript, const RString &sName, RString &sError, int iArgs = 0, int iReturnValues = 0 );
/* Run the given expression, returning a single value, and leave the return value on the
* stack. On error, push nil. */