Exemplo n.º 1
0
/* Run the function at the top of the stack, which returns an actor description
 * table.  If the table was returned, return true and leave it on the stack.
 * If not, display an error, return false, and leave nothing on the stack. */
bool ActorUtil::LoadTableFromStackShowErrors( Lua *L )
{
	LuaReference func;
	lua_pushvalue( L, -1 );
	func.SetFromStack( L );

	RString Error= "Lua runtime error: ";
	if( !LuaHelpers::RunScriptOnStack(L, Error, 0, 1, true) )
	{
		lua_pop( L, 1 );
		return false;
	}

	if( lua_type(L, -1) != LUA_TTABLE )
	{
		lua_pop( L, 1 );

		func.PushSelf( L );
		lua_Debug debug;
		lua_getinfo( L, ">nS", &debug );

		Error = ssprintf( "%s: must return a table", debug.short_src );

		LuaHelpers::ReportScriptError(Error, "LUA_ERROR");
		return false;
	}
	return true;
}
Exemplo n.º 2
0
apActorCommands ActorUtil::ParseActorCommands( const RString &sCommands, const RString &sName )
{
	Lua *L = LUA->Get();
	LuaHelpers::ParseCommandList( L, sCommands, sName, false );
	LuaReference *pRet = new LuaReference;
	pRet->SetFromStack( L );
	LUA->Release( L );

	return apActorCommands( pRet );
}
Exemplo n.º 3
0
static void GetGlobalTable( Lua *L )
{
	static LuaReference UserDataTable;
	if( !UserDataTable.IsSet() )
	{
		lua_newtable( L );
		UserDataTable.SetFromStack( L );
	}

	UserDataTable.PushSelf( L );
}
Exemplo n.º 4
0
void LuaTable::setReference(const LuaReference& ref) {
	ref->pushValue();

	lua_State* L = ref->getState();

	if (lua_type(L, -1) != LUA_TTABLE) {
		lua_pop(L, 1);
		throw LuaException("Reference does not refere to a table!");
	} else {
		lua_pop(L, 1);
		LuaValue::setReference(ref);
	}
}
Exemplo n.º 5
0
void LuaFunction::setReference(LuaReference ref) {
	ref->pushValue();

	lua_State* L = ref->getState();

	if (lua_type(L, -1) != LUA_TFUNCTION) {
		lua_pop(L, 1);
		throw LuaException("Reference does not refere to a function!");
	} else {
		lua_pop(L, 1);
		LuaValue::setReference(ref);
	}
}
Exemplo n.º 6
0
	static int Broadcast( T* p, lua_State *L )
	{
		if( !lua_istable(L, 2) && !lua_isnoneornil(L, 2) )
			luaL_typerror( L, 2, "table or nil" );

		LuaReference ParamTable;
		lua_pushvalue( L, 2 );
		ParamTable.SetFromStack( L );

		Message msg( SArg(1), ParamTable );
		p->Broadcast( msg );
		COMMON_RETURN_SELF;
	}
Exemplo n.º 7
0
void Message::SetParamTable( const LuaReference &params )
{
	Lua *L = LUA->Get();
	params.PushSelf( L );
	m_pParams->SetFromStack( L );
	LUA->Release( L );
}
Exemplo n.º 8
0
void ActorScroller::LoadFromNode( const XNode *pNode )
{
	ActorFrame::LoadFromNode( pNode );

	Load2();

	float fNumItemsToDraw = 0;
	if( pNode->GetAttrValue("NumItemsToDraw", fNumItemsToDraw) )
		SetNumItemsToDraw( fNumItemsToDraw );

	float fSecondsPerItem = 0;
	if( pNode->GetAttrValue("SecondsPerItem", fSecondsPerItem) )
		ActorScroller::SetSecondsPerItem( fSecondsPerItem );

	Lua *L = LUA->Get();
	pNode->PushAttrValue( L, "TransformFunction" );
	{
		LuaReference ref;
		ref.SetFromStack( L );
		if( !ref.IsNil() )
			SetTransformFromReference( ref );
	}
	LUA->Release( L );

	int iSubdivisions = 1;
	if( pNode->GetAttrValue("Subdivisions", iSubdivisions) )
		ActorScroller::SetNumSubdivisions( iSubdivisions );

	bool bUseMask = false;
	pNode->GetAttrValue( "UseMask", bUseMask );

	if( bUseMask )
	{
		pNode->GetAttrValue( "MaskWidth", m_fMaskWidth );
		pNode->GetAttrValue( "MaskHeight", m_fMaskHeight );
		EnableMask( m_fMaskWidth, m_fMaskHeight );
	}

	pNode->GetAttrValue( "QuantizePixels", m_fQuantizePixels );
	pNode->GetAttrValue( "LoopScroller", m_bLoop );
	pNode->GetAttrValue( "WrapScroller", m_bWrap );
}
Exemplo n.º 9
0
Message::Message( const RString &s, const LuaReference &params )
{
	m_sName = s;
	m_bBroadcast = false;
	Lua *L = LUA->Get();
	m_pParams = new LuaTable; // XXX: creates an extra table
	params.PushSelf( L );
	m_pParams->SetFromStack( L );
	LUA->Release( L );
//	m_pParams = new LuaTable( params );
}
Exemplo n.º 10
0
/* Set up the enum table on the stack, and pop the table. */
void Enum::SetMetatable( lua_State *L, LuaReference &EnumTable, LuaReference &EnumIndexTable, const char *szName )
{
	EnumTable.PushSelf( L );
	{
		lua_newtable( L );
		EnumIndexTable.PushSelf( L );
		lua_setfield( L, -2, "reverse" );

		lua_pushstring( L, szName );
		lua_setfield( L, -2, "name" );

		PushEnumMethodTable( L );
		lua_setfield( L, -2, "__index" );

		lua_pushliteral( L, "Enum" );
		LuaHelpers::PushValueFunc( L, 1 );
		lua_setfield( L, -2, "__type" ); // for luaL_pushtype
	}
	lua_setmetatable( L, -2 );
	lua_pop( L, 2 );
}
Exemplo n.º 11
0
void LuaValue::setReference(LuaReference ref) {
	this->_reference = ref;

	if (isValid()) {
		this->_reference->pushValue();

		_luaState = ref->getState();
		this->_luaType = luaToEnumType(lua_type(_luaState, -1));

		lua_pop(_luaState, 1);
	}
}
Exemplo n.º 12
0
int CheckEnum( lua_State *L, LuaReference &table, int iPos, int iInvalid, const char *szType, bool bAllowInvalid )
{
	luaL_checkany( L, iPos );

	if( lua_isnil(L, iPos) )
	{
		if( bAllowInvalid )
			return iInvalid;

		LuaHelpers::Push( L, ssprintf("Expected %s; got nil", szType) );
		lua_error( L );
	}

	iPos = LuaHelpers::AbsIndex( L, iPos );

	table.PushSelf( L );
	lua_pushvalue( L, iPos );
	lua_gettable( L, -2 );

	// If the result is nil, then a string was passed that is not a member of this enum.  Throw
	// an error.  To specify the invalid value, pass nil.  That way, typos will throw an error,
	// and not silently result in nil, or an out-of-bounds value.
	if( unlikely(lua_isnil(L, -1)) )
	{
		RString sGot;
		if( lua_isstring(L, iPos) )
		{
			/* We were given a string, but it wasn't a valid value for this enum.  Show
			 * the string. */
			lua_pushvalue( L, iPos );
			LuaHelpers::Pop( L, sGot );
			sGot = ssprintf( "\"%s\"", sGot.c_str() );
		}
		else
		{
			/* We didn't get a string.  Show the type. */
			luaL_pushtype( L, iPos );
			LuaHelpers::Pop( L, sGot );
		}
		LuaHelpers::Push( L, ssprintf("Expected %s; got %s", szType, sGot.c_str() ) );
		lua_error( L );
	}
	int iRet = lua_tointeger( L, -1 );
	lua_pop( L, 2 );
	return iRet;
}
Exemplo n.º 13
0
	template<> bool FromStack<LuaReference>( lua_State *L, LuaReference &Object, int iOffset )
	{
		lua_pushvalue( L, iOffset );
		Object.SetFromStack( L );
		return true;
	}
Exemplo n.º 14
0
	template<> void Push<LuaReference>( lua_State *L, const LuaReference &Object ) 
	{
		Object.PushSelf( L );
	}
Exemplo n.º 15
0
void XNodeLuaValue::SetValueFromStack( lua_State *L )
{
	m_Value.SetFromStack( L );
}
Exemplo n.º 16
0
LuaReference UniqueLuaReference::copy(const LuaReference& other) {
	other->pushValue();

	return create(other->_luaState);
}
Exemplo n.º 17
0
void ActorScroller::SetTransformFromExpression( const std::string &sTransformFunction )
{
	LuaReference ref;
	ref.SetFromExpression( sTransformFunction );
	SetTransformFromReference( ref );
}
Exemplo n.º 18
0
void XNodeLuaValue::PushValue( lua_State *L ) const
{
	m_Value.PushSelf( L );
}
Exemplo n.º 19
0
int CheckEnum( lua_State *L, LuaReference &table, int iPos, int iInvalid, const char *szType, bool bAllowInvalid, bool bAllowAnything )
{
	luaL_checkany( L, iPos );

	if( lua_isnil(L, iPos) )
	{
		if( bAllowInvalid )
			return iInvalid;

		LuaHelpers::Push( L, ssprintf("Expected %s; got nil", szType) );
		lua_error( L );
	}

	iPos = LuaHelpers::AbsIndex( L, iPos );

	table.PushSelf( L );
	lua_pushvalue( L, iPos );
	lua_gettable( L, -2 );

	// If not found, check case-insensitively for legacy compatibility
	if( lua_isnil(L, -1) && lua_isstring(L, iPos) ) {
		RString sLower;

		// Get rid of nil value on stack
		lua_pop( L, 1 );

		// Get the string and lowercase it
		lua_pushvalue( L, iPos );
		LuaHelpers::Pop( L, sLower );
		sLower.MakeLower();

		// Try again to read the value
		table.PushSelf( L );
		LuaHelpers::Push( L, sLower );
		lua_gettable( L, -2 );
	}

	// If the result is nil, then a string was passed that is not a member of this enum.  Throw
	// an error.  To specify the invalid value, pass nil.  That way, typos will throw an error,
	// and not silently result in nil, or an out-of-bounds value.
	if( unlikely(lua_isnil(L, -1)) )
	{
		RString sGot;
		if( lua_isstring(L, iPos) )
		{
			/* We were given a string, but it wasn't a valid value for this enum.  Show
			 * the string. */
			lua_pushvalue( L, iPos );
			LuaHelpers::Pop( L, sGot );
			sGot = ssprintf( "\"%s\"", sGot.c_str() );
		}
		else
		{
			/* We didn't get a string.  Show the type. */
			luaL_pushtype( L, iPos );
			LuaHelpers::Pop( L, sGot );
		}
		LuaHelpers::Push( L, ssprintf("Expected %s; got %s", szType, sGot.c_str() ) );
		// There are a couple places where CheckEnum is used outside of a
		// function called from lua.  If we use lua_error from one of them,
		// StepMania crashes out completely.  bAllowAnything allows those places
		// to avoid crashing over theme mistakes.
		if(bAllowAnything)
		{
			RString errmsg;
			LuaHelpers::Pop(L, errmsg);
			LOG->Warn(errmsg.c_str());
			lua_pop(L, 2);
			return iInvalid;
		}
		lua_error( L );
	}
	int iRet = lua_tointeger( L, -1 );
	lua_pop( L, 2 );
	return iRet;
}