add LuaReference::GetLuaType, LuaExpression
This commit is contained in:
@@ -66,6 +66,14 @@ bool LuaReference::IsSet() const
|
|||||||
return m_iReference != LUA_NOREF;
|
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()
|
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
|
* (c) 2005 Glenn Maynard, Chris Danford
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ public:
|
|||||||
/* Return true if set. (SetFromNil() counts as being set.) */
|
/* Return true if set. (SetFromNil() counts as being set.) */
|
||||||
bool IsSet() const;
|
bool IsSet() const;
|
||||||
|
|
||||||
|
/* Return the referenced type, or LUA_TNONE if not set. */
|
||||||
|
int GetLuaType() const;
|
||||||
|
|
||||||
static void ReRegisterAll(); // call this after resetting Lua
|
static void ReRegisterAll(); // call this after resetting Lua
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -40,6 +43,20 @@ private:
|
|||||||
int m_iReference;
|
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
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user