From e24c79048ee3aae1322c814b4fdf8e4022f809b7 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 14 Feb 2005 01:31:10 +0000 Subject: [PATCH] add LuaReference::GetLuaType, LuaExpression --- stepmania/src/LuaReference.cpp | 22 ++++++++++++++++++++++ stepmania/src/LuaReference.h | 17 +++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/stepmania/src/LuaReference.cpp b/stepmania/src/LuaReference.cpp index 906e66a1b7..5ed72d82f5 100644 --- a/stepmania/src/LuaReference.cpp +++ b/stepmania/src/LuaReference.cpp @@ -66,6 +66,14 @@ bool LuaReference::IsSet() const return m_iReference != LUA_NOREF; } +int LuaReference::GetLuaType() const +{ + this->PushSelf(); + int iRet = lua_type( LUA->L, -1 ); + lua_pop( LUA->L, 1 ); + return iRet; +} + void LuaReference::Register() { } @@ -98,6 +106,20 @@ void LuaReference::ReRegister() } +void LuaExpression::SetFromExpression( const CString &sExpression ) +{ + m_sExpression = sExpression; + Register(); +} + +void LuaExpression::Register() +{ + LUA->RunScript( "return " + m_sExpression, 1 ); + + /* Store the result. */ + this->SetFromStack(); +} + /* * (c) 2005 Glenn Maynard, Chris Danford * All rights reserved. diff --git a/stepmania/src/LuaReference.h b/stepmania/src/LuaReference.h index 4ce5187bf1..97ff13a701 100644 --- a/stepmania/src/LuaReference.h +++ b/stepmania/src/LuaReference.h @@ -26,6 +26,9 @@ public: /* Return true if set. (SetFromNil() counts as being set.) */ bool IsSet() const; + /* Return the referenced type, or LUA_TNONE if not set. */ + int GetLuaType() const; + static void ReRegisterAll(); // call this after resetting Lua protected: @@ -40,6 +43,20 @@ private: int m_iReference; }; +/* Evaluate an expression that returns an object; store the object in a reference. + * For example, evaluating "{ 1, 2, 3 }" will result in a reference to a table. */ +class LuaExpression: public LuaReference +{ +public: + void SetFromExpression( const CString &sExpression ); + +protected: + virtual void Register(); + +private: + CString m_sExpression; +}; + #endif /*