2004-02-14 21:08:12 +00:00
|
|
|
#include "global.h"
|
2005-01-24 02:26:55 +00:00
|
|
|
#include "LuaManager.h"
|
2004-02-14 21:08:12 +00:00
|
|
|
#include "LuaFunctions.h"
|
2005-02-13 04:09:28 +00:00
|
|
|
#include "LuaReference.h"
|
2004-02-14 21:08:12 +00:00
|
|
|
#include "RageUtil.h"
|
|
|
|
|
#include "RageLog.h"
|
2005-01-19 23:33:19 +00:00
|
|
|
#include "RageFile.h"
|
2004-11-07 10:36:59 +00:00
|
|
|
#include "arch/Dialog/Dialog.h"
|
2005-01-24 02:04:03 +00:00
|
|
|
#include "Foreach.h"
|
2004-02-14 21:08:12 +00:00
|
|
|
|
2004-04-05 05:22:32 +00:00
|
|
|
#include <csetjmp>
|
|
|
|
|
#include <cassert>
|
2004-02-14 21:08:12 +00:00
|
|
|
|
2005-01-19 23:33:19 +00:00
|
|
|
LuaManager *LUA = NULL;
|
|
|
|
|
static LuaFunctionList *g_LuaFunctions = NULL;
|
2004-02-14 21:08:12 +00:00
|
|
|
|
|
|
|
|
#if defined(_WINDOWS)
|
2004-06-20 02:41:53 +00:00
|
|
|
#pragma comment(lib, "lua-5.0/lib/LibLua.lib")
|
|
|
|
|
#pragma comment(lib, "lua-5.0/lib/LibLuaLib.lib")
|
2004-06-20 01:35:25 +00:00
|
|
|
#endif
|
|
|
|
|
#if defined(_XBOX)
|
2004-06-20 02:41:53 +00:00
|
|
|
#pragma comment(lib, "lua-5.0/lib/LibLuaXbox.lib")
|
|
|
|
|
#pragma comment(lib, "lua-5.0/lib/LibLuaLibXbox.lib")
|
2004-06-20 01:35:25 +00:00
|
|
|
#endif
|
|
|
|
|
#if defined(_WINDOWS) || defined (_XBOX)
|
2004-02-14 21:08:12 +00:00
|
|
|
/* "interaction between '_setjmp' and C++ object destruction is non-portable"
|
|
|
|
|
* We don't care; we'll throw a fatal exception immediately anyway. */
|
|
|
|
|
#pragma warning (disable : 4611)
|
|
|
|
|
#endif
|
2004-05-26 20:52:42 +00:00
|
|
|
#if defined (DARWIN)
|
|
|
|
|
extern void NORETURN longjmp(jmp_buf env, int val);
|
|
|
|
|
#endif
|
2004-02-14 21:08:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct ChunkReaderData
|
|
|
|
|
{
|
|
|
|
|
const CString *buf;
|
|
|
|
|
bool done;
|
|
|
|
|
ChunkReaderData() { buf = NULL; done = false; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const char *ChunkReaderString( lua_State *L, void *ptr, size_t *size )
|
|
|
|
|
{
|
|
|
|
|
ChunkReaderData *data = (ChunkReaderData *) ptr;
|
|
|
|
|
if( data->done )
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
data->done = true;
|
|
|
|
|
|
|
|
|
|
*size = data->buf->size();
|
|
|
|
|
const char *ret = data->buf->data();
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-30 02:01:27 +00:00
|
|
|
void LuaManager::PushStackNil()
|
2004-02-14 21:08:12 +00:00
|
|
|
{
|
2005-01-30 02:01:27 +00:00
|
|
|
lua_pushnil( L );
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-05 23:03:20 +00:00
|
|
|
void LuaManager::PushNopFunction()
|
|
|
|
|
{
|
|
|
|
|
lua_rawgeti( LUA->L, LUA_REGISTRYINDEX, m_iNopFunction );
|
|
|
|
|
|
|
|
|
|
ASSERT_M( !lua_isnil(L, -1), ssprintf("%i", m_iNopFunction) )
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-30 02:01:27 +00:00
|
|
|
void LuaManager::PushStack( int out, lua_State *L )
|
|
|
|
|
{
|
|
|
|
|
if( L == NULL )
|
|
|
|
|
L = LUA->L;
|
|
|
|
|
|
2004-02-14 21:08:12 +00:00
|
|
|
/* XXX: stack bounds */
|
|
|
|
|
lua_pushnumber( L, out );
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-30 02:01:27 +00:00
|
|
|
void LuaManager::PushStack( bool out, lua_State *L )
|
2004-02-14 21:08:12 +00:00
|
|
|
{
|
2005-01-30 02:01:27 +00:00
|
|
|
if( L == NULL )
|
|
|
|
|
L = LUA->L;
|
|
|
|
|
|
2004-02-14 21:08:12 +00:00
|
|
|
/* XXX: stack bounds */
|
|
|
|
|
lua_pushboolean( L, out );
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-30 02:01:27 +00:00
|
|
|
void LuaManager::PushStack( float val, lua_State *L )
|
|
|
|
|
{
|
|
|
|
|
if( L == NULL )
|
|
|
|
|
L = LUA->L;
|
2004-02-14 21:08:12 +00:00
|
|
|
|
2005-01-30 02:01:27 +00:00
|
|
|
/* XXX: stack bounds */
|
|
|
|
|
lua_pushnumber( L, val );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LuaManager::PushStack( void *out, lua_State *L )
|
2004-02-14 21:08:12 +00:00
|
|
|
{
|
2005-01-30 02:01:27 +00:00
|
|
|
if( L == NULL )
|
|
|
|
|
L = LUA->L;
|
|
|
|
|
|
2004-02-14 21:08:12 +00:00
|
|
|
if( out )
|
|
|
|
|
lua_pushlightuserdata( L, out );
|
|
|
|
|
else
|
|
|
|
|
lua_pushnil( L );
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-30 02:01:27 +00:00
|
|
|
void LuaManager::PushStack( const CString &out, lua_State *L )
|
2004-02-14 21:08:12 +00:00
|
|
|
{
|
2005-01-30 02:01:27 +00:00
|
|
|
if( L == NULL )
|
|
|
|
|
L = LUA->L;
|
2004-02-14 21:08:12 +00:00
|
|
|
lua_pushstring( L, out );
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-13 04:09:28 +00:00
|
|
|
void LuaManager::CreateTableFromArray( const vector<bool> &aIn, lua_State *L )
|
|
|
|
|
{
|
|
|
|
|
if( L == NULL )
|
|
|
|
|
L = LUA->L;
|
|
|
|
|
|
|
|
|
|
lua_newtable( L );
|
|
|
|
|
for( unsigned i = 0; i < aIn.size(); ++i )
|
|
|
|
|
{
|
|
|
|
|
lua_pushboolean( L, aIn[i] );
|
|
|
|
|
lua_rawseti( L, -2, i+1 );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LuaManager::ReadArrayFromTable( vector<bool> &aOut, lua_State *L )
|
|
|
|
|
{
|
|
|
|
|
if( L == NULL )
|
|
|
|
|
L = LUA->L;
|
|
|
|
|
|
|
|
|
|
luaL_checktype( L, -1, LUA_TTABLE );
|
|
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < aOut.size(); ++i )
|
|
|
|
|
{
|
|
|
|
|
lua_rawgeti( L, -1, i+1 );
|
|
|
|
|
bool bOn = !!lua_toboolean( L, -1 );
|
|
|
|
|
aOut[i] = bOn;
|
|
|
|
|
lua_pop( L, 1 );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-19 23:01:53 +00:00
|
|
|
void LuaManager::PopStack( CString &out )
|
2004-02-14 21:08:12 +00:00
|
|
|
{
|
|
|
|
|
/* There must be at least one entry on the stack. */
|
|
|
|
|
ASSERT( lua_gettop(L) > 0 );
|
|
|
|
|
ASSERT( lua_isstring(L, -1) );
|
|
|
|
|
|
|
|
|
|
out = lua_tostring( L, -1 );
|
|
|
|
|
lua_pop( L, -1 );
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-19 23:01:53 +00:00
|
|
|
bool LuaManager::GetStack( int pos, int &out )
|
2004-02-25 23:58:47 +00:00
|
|
|
{
|
|
|
|
|
if( pos < 0 )
|
|
|
|
|
pos = lua_gettop(L) - pos - 1;
|
|
|
|
|
if( pos < 1 )
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
out = (int) lua_tonumber( L, pos );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-19 23:01:53 +00:00
|
|
|
void LuaManager::SetGlobal( const CString &sName )
|
2005-01-09 01:31:06 +00:00
|
|
|
{
|
|
|
|
|
lua_setglobal( L, sName );
|
|
|
|
|
}
|
2004-02-14 21:08:12 +00:00
|
|
|
|
|
|
|
|
|
2004-02-24 08:00:04 +00:00
|
|
|
static int LuaPanic( lua_State *L )
|
2004-02-14 21:08:12 +00:00
|
|
|
{
|
2005-01-28 19:42:44 +00:00
|
|
|
CString sErr;
|
|
|
|
|
LUA->PopStack( sErr );
|
|
|
|
|
|
|
|
|
|
RageException::Throw( "%s", sErr.c_str() );
|
2004-02-14 21:08:12 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-24 02:04:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// Actor registration
|
2005-02-05 10:15:15 +00:00
|
|
|
static vector<RegisterActorFn> *g_vRegisterActorTypes = NULL;
|
2005-01-24 02:04:03 +00:00
|
|
|
|
|
|
|
|
void LuaManager::Register( RegisterActorFn pfn )
|
|
|
|
|
{
|
2005-02-05 10:15:15 +00:00
|
|
|
if( g_vRegisterActorTypes == NULL )
|
|
|
|
|
g_vRegisterActorTypes = new vector<RegisterActorFn>;
|
2005-01-24 02:04:03 +00:00
|
|
|
|
2005-02-05 10:15:15 +00:00
|
|
|
g_vRegisterActorTypes->push_back( pfn );
|
2005-01-24 02:04:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-01-19 22:27:24 +00:00
|
|
|
LuaManager::LuaManager()
|
2004-02-14 21:08:12 +00:00
|
|
|
{
|
2005-01-24 02:04:03 +00:00
|
|
|
LUA = this; // so that LUA is available when we call the Register functions
|
|
|
|
|
|
2005-01-19 23:33:19 +00:00
|
|
|
L = NULL;
|
|
|
|
|
|
2005-01-24 03:05:37 +00:00
|
|
|
ResetState();
|
2005-01-19 23:33:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LuaManager::~LuaManager()
|
|
|
|
|
{
|
|
|
|
|
lua_close( L );
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-24 03:05:37 +00:00
|
|
|
void LuaManager::ResetState()
|
2005-01-19 23:33:19 +00:00
|
|
|
{
|
|
|
|
|
if( L != NULL )
|
|
|
|
|
lua_close( L );
|
|
|
|
|
|
2004-09-22 04:55:31 +00:00
|
|
|
L = lua_open();
|
2004-02-14 21:08:12 +00:00
|
|
|
ASSERT( L );
|
|
|
|
|
|
|
|
|
|
lua_atpanic( L, LuaPanic );
|
|
|
|
|
|
|
|
|
|
luaopen_base( L );
|
2004-02-15 00:42:45 +00:00
|
|
|
luaopen_math( L );
|
|
|
|
|
luaopen_string( L );
|
2004-02-14 21:08:12 +00:00
|
|
|
lua_settop(L, 0); // luaopen_* pushes stuff onto the stack that we don't need
|
|
|
|
|
|
2005-02-05 23:03:20 +00:00
|
|
|
/* Set up the NOP function pointer. */
|
|
|
|
|
RunScript( "return function() end", 1 );
|
|
|
|
|
m_iNopFunction = luaL_ref( L, LUA_REGISTRYINDEX );
|
2005-02-02 03:36:46 +00:00
|
|
|
|
2005-01-19 23:33:19 +00:00
|
|
|
for( const LuaFunctionList *p = g_LuaFunctions; p; p=p->next )
|
|
|
|
|
lua_register( L, p->name, p->func );
|
2005-01-24 02:04:03 +00:00
|
|
|
|
2005-02-05 10:15:15 +00:00
|
|
|
if( g_vRegisterActorTypes )
|
2005-01-24 02:04:03 +00:00
|
|
|
{
|
2005-02-05 10:15:15 +00:00
|
|
|
for( unsigned i=0; i<g_vRegisterActorTypes->size(); i++ )
|
2005-01-26 11:21:43 +00:00
|
|
|
{
|
2005-02-05 10:15:15 +00:00
|
|
|
RegisterActorFn fn = (*g_vRegisterActorTypes)[i];
|
2005-01-26 11:21:43 +00:00
|
|
|
fn( L );
|
|
|
|
|
}
|
2005-01-24 02:04:03 +00:00
|
|
|
}
|
2005-02-05 10:15:15 +00:00
|
|
|
|
2005-02-13 04:09:28 +00:00
|
|
|
LuaReference::ReRegisterAll();
|
2004-09-22 04:55:31 +00:00
|
|
|
}
|
2004-02-14 21:08:12 +00:00
|
|
|
|
2005-01-19 22:27:24 +00:00
|
|
|
void LuaManager::PrepareExpression( CString &sInOut )
|
2004-11-06 06:00:58 +00:00
|
|
|
{
|
|
|
|
|
// HACK: Many metrics have "//" comments that Lua fails to parse.
|
|
|
|
|
// Replace them with Lua-style comments.
|
|
|
|
|
sInOut.Replace( "//", "--" );
|
2004-11-06 18:56:39 +00:00
|
|
|
|
|
|
|
|
// comment out HTML style color values
|
|
|
|
|
sInOut.Replace( "#", "--" );
|
2004-11-07 06:07:34 +00:00
|
|
|
|
2004-11-06 06:00:58 +00:00
|
|
|
// Remove leading +, eg. "+50"; Lua doesn't handle that.
|
|
|
|
|
if( sInOut.size() >= 1 && sInOut[0] == '+' )
|
|
|
|
|
sInOut.erase( 0, 1 );
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-19 23:33:19 +00:00
|
|
|
bool LuaManager::RunScriptFile( const CString &sFile )
|
|
|
|
|
{
|
|
|
|
|
RageFile f;
|
|
|
|
|
if( !f.Open( sFile ) )
|
|
|
|
|
{
|
2005-02-12 22:53:51 +00:00
|
|
|
CString sError = ssprintf( "Couldn't open Lua script \"%s\": %s", sFile.c_str(), f.GetError().c_str() );
|
|
|
|
|
Dialog::OK( sError, "LUA_ERROR" );
|
2005-01-19 23:33:19 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CString sScript;
|
|
|
|
|
if( f.Read( sScript ) == -1 )
|
|
|
|
|
{
|
2005-02-12 22:53:51 +00:00
|
|
|
CString sError = ssprintf( "Error reading Lua script \"%s\": %s", sFile.c_str(), f.GetError().c_str() );
|
|
|
|
|
Dialog::OK( sError, "LUA_ERROR" );
|
2005-01-19 23:33:19 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return RunScript( sScript );
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-05 23:03:20 +00:00
|
|
|
bool LuaManager::RunScript( const CString &sScript, int iReturnValues )
|
2004-09-22 04:55:31 +00:00
|
|
|
{
|
2005-01-19 23:33:19 +00:00
|
|
|
// load string
|
|
|
|
|
{
|
|
|
|
|
ChunkReaderData data;
|
|
|
|
|
data.buf = &sScript;
|
|
|
|
|
int ret = lua_load( L, ChunkReaderString, &data, "in" );
|
|
|
|
|
|
|
|
|
|
if( ret )
|
|
|
|
|
{
|
|
|
|
|
CString err;
|
|
|
|
|
LuaManager::PopStack( err );
|
|
|
|
|
CString sError = ssprintf( "Lua runtime error parsing \"%s\": %s", sScript.c_str(), err.c_str() );
|
|
|
|
|
Dialog::OK( sError, "LUA_ERROR" );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ASSERT_M( lua_gettop(L) == 1, ssprintf("%i", lua_gettop(L)) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// evaluate
|
|
|
|
|
{
|
2005-02-05 23:03:20 +00:00
|
|
|
int ret = lua_pcall( L, 0, iReturnValues, 0 );
|
2005-01-19 23:33:19 +00:00
|
|
|
if( ret )
|
|
|
|
|
{
|
|
|
|
|
CString err;
|
|
|
|
|
LuaManager::PopStack( err );
|
|
|
|
|
CString sError = ssprintf( "Lua runtime error evaluating \"%s\": %s", sScript.c_str(), err.c_str() );
|
|
|
|
|
Dialog::OK( sError, "LUA_ERROR" );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2005-01-19 23:01:53 +00:00
|
|
|
|
2005-02-12 22:53:51 +00:00
|
|
|
|
2005-01-19 23:33:19 +00:00
|
|
|
bool LuaManager::RunExpression( const CString &str )
|
|
|
|
|
{
|
2004-11-07 18:07:54 +00:00
|
|
|
// load string
|
2004-02-14 21:08:12 +00:00
|
|
|
{
|
2004-11-07 18:07:54 +00:00
|
|
|
ChunkReaderData data;
|
|
|
|
|
CString sStatement = "return " + str;
|
|
|
|
|
data.buf = &sStatement;
|
|
|
|
|
int ret = lua_load( L, ChunkReaderString, &data, "in" );
|
|
|
|
|
|
|
|
|
|
if( ret )
|
|
|
|
|
{
|
|
|
|
|
CString err;
|
2005-01-19 23:01:53 +00:00
|
|
|
LuaManager::PopStack( err );
|
2004-12-02 05:56:38 +00:00
|
|
|
CString sError = ssprintf( "Lua runtime error parsing \"%s\": %s", str.c_str(), err.c_str() );
|
2004-11-07 18:07:54 +00:00
|
|
|
Dialog::OK( sError, "LUA_ERROR" );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ASSERT_M( lua_gettop(L) == 1, ssprintf("%i", lua_gettop(L)) );
|
2004-02-14 21:08:12 +00:00
|
|
|
}
|
|
|
|
|
|
2004-11-07 18:07:54 +00:00
|
|
|
// evaluate
|
|
|
|
|
{
|
|
|
|
|
int ret = lua_pcall(L, 0, 1, 0);
|
|
|
|
|
if( ret )
|
|
|
|
|
{
|
|
|
|
|
CString err;
|
2005-01-19 23:01:53 +00:00
|
|
|
LuaManager::PopStack( err );
|
2004-12-02 05:56:38 +00:00
|
|
|
CString sError = ssprintf( "Lua runtime error evaluating \"%s\": %s", str.c_str(), err.c_str() );
|
2004-11-07 18:07:54 +00:00
|
|
|
Dialog::OK( sError, "LUA_ERROR" );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ASSERT_M( lua_gettop(L) == 1, ssprintf("%i", lua_gettop(L)) );
|
|
|
|
|
|
|
|
|
|
/* Don't accept a function as a return value; if you really want to use a function
|
|
|
|
|
* as a boolean, convert it before returning. */
|
|
|
|
|
if( lua_isfunction( L, -1 ) )
|
2004-11-30 08:22:40 +00:00
|
|
|
RageException::Throw( "result is a function; did you forget \"()\"?" );
|
2004-11-07 18:07:54 +00:00
|
|
|
}
|
2004-05-03 04:38:08 +00:00
|
|
|
|
2004-11-07 18:07:54 +00:00
|
|
|
return true;
|
2004-09-22 04:55:31 +00:00
|
|
|
}
|
2004-05-03 04:38:08 +00:00
|
|
|
|
2005-01-19 22:27:24 +00:00
|
|
|
bool LuaManager::RunExpressionB( const CString &str )
|
2004-09-22 04:55:31 +00:00
|
|
|
{
|
2004-12-01 02:37:18 +00:00
|
|
|
if( !RunExpression( str ) )
|
|
|
|
|
return false;
|
2004-09-22 04:55:31 +00:00
|
|
|
|
2004-12-01 02:37:18 +00:00
|
|
|
bool result = !!lua_toboolean( L, -1 );
|
|
|
|
|
lua_pop( L, -1 );
|
2004-02-14 21:08:12 +00:00
|
|
|
|
2004-12-01 02:37:18 +00:00
|
|
|
return result;
|
2004-02-14 21:08:12 +00:00
|
|
|
}
|
2004-09-22 04:55:31 +00:00
|
|
|
|
2005-01-19 22:27:24 +00:00
|
|
|
float LuaManager::RunExpressionF( const CString &str )
|
2004-09-22 04:55:31 +00:00
|
|
|
{
|
2004-12-01 02:37:18 +00:00
|
|
|
if( !RunExpression( str ) )
|
|
|
|
|
return 0;
|
2004-09-22 04:55:31 +00:00
|
|
|
|
2004-12-01 02:37:18 +00:00
|
|
|
float result = (float) lua_tonumber( L, -1 );
|
|
|
|
|
lua_pop( L, -1 );
|
2004-09-22 04:55:31 +00:00
|
|
|
|
2004-12-01 02:37:18 +00:00
|
|
|
return result;
|
2004-02-14 21:08:12 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-19 22:27:24 +00:00
|
|
|
bool LuaManager::RunExpressionS( const CString &str, CString &sOut )
|
2005-01-16 20:36:27 +00:00
|
|
|
{
|
|
|
|
|
if( !RunExpression( str ) )
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
ASSERT( lua_gettop(L) > 0 );
|
|
|
|
|
|
|
|
|
|
sOut = lua_tostring( L, -1 );
|
|
|
|
|
lua_pop( L, -1 );
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-20 01:08:26 +00:00
|
|
|
bool LuaManager::RunAtExpression( CString &sStr )
|
|
|
|
|
{
|
|
|
|
|
if( sStr.size() == 0 || sStr[0] != '@' )
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* Erase "@". */
|
|
|
|
|
sStr.erase( 0, 1 );
|
|
|
|
|
|
|
|
|
|
CString sOut;
|
|
|
|
|
RunExpressionS( sStr, sOut );
|
|
|
|
|
sStr = sOut;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-19 23:01:53 +00:00
|
|
|
void LuaManager::Fail( const CString &err )
|
2004-02-14 21:08:12 +00:00
|
|
|
{
|
|
|
|
|
lua_pushstring( L, err );
|
|
|
|
|
lua_error( L );
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-24 02:04:03 +00:00
|
|
|
|
2004-02-14 21:08:12 +00:00
|
|
|
LuaFunctionList::LuaFunctionList( CString name_, lua_CFunction func_ )
|
|
|
|
|
{
|
|
|
|
|
name = name_;
|
|
|
|
|
func = func_;
|
2005-01-19 23:33:19 +00:00
|
|
|
next = g_LuaFunctions;
|
|
|
|
|
g_LuaFunctions = this;
|
2004-02-14 21:08:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-25 23:58:47 +00:00
|
|
|
LuaFunction_NoArgs( MonthOfYear, GetLocalTime().tm_mon+1 );
|
2004-02-14 21:08:12 +00:00
|
|
|
LuaFunction_NoArgs( DayOfMonth, GetLocalTime().tm_mday );
|
|
|
|
|
LuaFunction_NoArgs( Hour, GetLocalTime().tm_hour );
|
|
|
|
|
LuaFunction_NoArgs( Minute, GetLocalTime().tm_min );
|
|
|
|
|
LuaFunction_NoArgs( Second, GetLocalTime().tm_sec );
|
|
|
|
|
LuaFunction_NoArgs( Year, GetLocalTime().tm_year+1900 );
|
|
|
|
|
LuaFunction_NoArgs( Weekday, GetLocalTime().tm_wday );
|
|
|
|
|
LuaFunction_NoArgs( DayOfYear, GetLocalTime().tm_yday );
|
|
|
|
|
|
2005-01-19 23:43:28 +00:00
|
|
|
LuaFunction_Str( Trace, (LOG->Trace("%s", str.c_str()),true) );
|
|
|
|
|
|
2004-02-14 21:08:12 +00:00
|
|
|
/*
|
2004-05-31 22:42:12 +00:00
|
|
|
* (c) 2004 Glenn Maynard
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
* distribute, and/or sell copies of the Software, and to permit persons to
|
|
|
|
|
* whom the Software is furnished to do so, provided that the above
|
|
|
|
|
* copyright notice(s) and this permission notice appear in all copies of
|
|
|
|
|
* the Software and that both the above copyright notice(s) and this
|
|
|
|
|
* permission notice appear in supporting documentation.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
|
|
|
|
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
|
|
|
|
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
|
|
|
|
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
|
|
|
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
|
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
2004-02-14 21:08:12 +00:00
|
|
|
*/
|