allow passing params to RunScript
This commit is contained in:
@@ -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
|
// 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
|
// evaluate
|
||||||
{
|
{
|
||||||
int ret = lua_pcall( L, 0, iReturnValues, 0 );
|
int ret = lua_pcall( L, iArgs, iReturnValues, 0 );
|
||||||
if( ret )
|
if( ret )
|
||||||
{
|
{
|
||||||
LuaHelpers::Pop( L, sError );
|
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 )
|
bool LuaHelpers::RunExpression( Lua *L, const RString &sExpression, const RString &sName )
|
||||||
{
|
{
|
||||||
RString sError;
|
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() );
|
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" );
|
||||||
@@ -627,7 +630,7 @@ void LuaHelpers::ParseCommandList( Lua *L, const RString &sCommands, const RStri
|
|||||||
}
|
}
|
||||||
|
|
||||||
RString sError;
|
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() );
|
LOG->Warn( "Compiling \"%s\": %s", sLuaFunction.c_str(), sError.c_str() );
|
||||||
|
|
||||||
/* The function is now on the stack. */
|
/* The function is now on the stack. */
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ namespace LuaHelpers
|
|||||||
/* Run a script with the given name. The given number of return values are left on
|
/* 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
|
* the Lua stack. On error, nils are left on the stack, sError is set and
|
||||||
* false is returned. */
|
* 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
|
/* Run the given expression, returning a single value, and leave the return value on the
|
||||||
* stack. On error, push nil. */
|
* stack. On error, push nil. */
|
||||||
|
|||||||
Reference in New Issue
Block a user