![]() |
wxIScan
|
A class to handle Lua scripting. More...
#include <wxluascript.h>
Public Member Functions | |
wxLuaScript (const wxString &strScript=wxEmptyString, wxEvtHandler *poParent=NULL, const wxString &strDomain=wxEmptyString, bool *pbParentState=NULL) | |
Standard constructor. | |
virtual | ~wxLuaScript () |
Virtual destructor. | |
virtual void | Run () |
Run the Lua script in memory. | |
virtual void | RegisterFunction (const wxString &strLuaCFunctionName, lua_CFunction pLuaCFunction) |
Register a new (LuaC-)function to Lua. | |
virtual void | RegisterConstant (const wxString &strLuaConstantName, const wxString &strValue) |
Register a string constant to Lua. | |
virtual void | RegisterConstant (const wxString &strLuaConstantName, const int nValue) |
Register an integer constant to Lua. | |
virtual void | RegisterVariable (const wxString &strLuaVarName, const int *pnValue) |
Register an integer variable to Lua. | |
virtual void | RegisterVariable (const wxString &strLuaVarName, const bool *pnValue) |
Register a boolean variable to Lua. | |
virtual void | RegisterVariable (const wxString &strLuaVarName, const double *pnValue) |
Register a double variable to Lua. | |
virtual void | RegisterVariable (const wxString &strLuaVarName, const wxString *pstrValue) |
Register a wxString variable to Lua. | |
virtual void | CallLuaFunction (const wxString &strLuaFunction) |
Call a Lua function without return value (sometimes called a 'procedure') by given name. | |
bool | IsOk () |
Returns the object state: true on OK and false otherwise. | |
Protected Types | |
typedef lua_State * | t_luaL_newstate () |
typedef void | t_luaL_openlibs (lua_State *) |
typedef lua_CFunction | t_lua_atpanic (lua_State *, lua_CFunction) |
typedef int | t_lua_error (lua_State *) |
typedef int | t_lua_gettop (lua_State *) |
typedef int | t_luaL_loadstring (lua_State *, const char *) |
typedef void | t_lua_pushstring (lua_State *, const char *) |
typedef void | t_lua_pushinteger (lua_State *, lua_Integer) |
typedef void | t_lua_pushboolean (lua_State *, int) |
typedef lua_Integer | t_lua_tointeger (lua_State *, int) |
typedef const char * | t_lua_tolstring (lua_State *, int, size_t *) |
typedef lua_Number | t_lua_tonumber (lua_State *, int) |
typedef int | t_lua_toboolean (lua_State *, int) |
typedef int | t_lua_isnumber (lua_State *, int) |
typedef int | t_lua_type (lua_State *, int) |
typedef int | t_lua_isstring (lua_State *, int) |
typedef void | t_lua_pushcclosure (lua_State *, lua_CFunction, int) |
typedef void | t_lua_call (lua_State *, int, int) |
typedef int | t_lua_pcall (lua_State *, int, int, int) |
typedef int | t_lua_cpcall (lua_State *, lua_CFunction, void *) |
typedef void | t_lua_settable (lua_State *, int) |
typedef void | t_lua_setfield (lua_State *, int, const char *) |
typedef void | t_lua_getfield (lua_State *, int, const char *) |
typedef void | t_lua_settop (lua_State *, int) |
typedef void | t_lua_insert (lua_State *, int) |
typedef void | t_lua_pushvalue (lua_State *, int) |
typedef void | t_lua_close (lua_State *) |
typedef void | t_lua_createtable (lua_State *, int, int) |
typedef void | t_lua_pushlightuserdata (lua_State *, void *) |
typedef const void * | t_lua_topointer (lua_State *, int) |
typedef void | t_lua_gettable (lua_State *, int) |
typedef void | t_lua_pushnumber (lua_State *, lua_Number) |
Static Protected Member Functions | |
static void | RegisterFunction (lua_State *L, const char *pszTableName, const char *pszFuncName, lua_CFunction pLuaCFunction) |
Register a new (LuaC-)function to Lua. Lower level function. | |
static wxLuaScript * | GetThis (lua_State *L) |
Get the this-pointer from Lua. | |
static int | Run (lua_State *L) |
Run the Lua script in memory in protected mode. | |
static int | TraceBack (lua_State *L) |
Create a stack trace on the Lua stack. | |
static int | LuaAtPanic (lua_State *L) |
Error handler for (maybe fatal) Lua errors. | |
static int | LogMessage (lua_State *L) |
Log a message on the standard wxWidgets log target. | |
static int | SendMenuEvent (lua_State *L) |
Send a menu event to the parent event handler. | |
static int | LuaIntVarAccessor (lua_State *L) |
Accessor function to a C-closure bound integer on the C/C++ side. | |
static int | LuaBoolVarAccessor (lua_State *L) |
Accessor function to a C-closure bound integer on the C/C++ side. | |
static int | LuaDoubleVarAccessor (lua_State *L) |
Accessor function to a C-closure bound integer on the C/C++ side. | |
static int | LuaStringVarAccessor (lua_State *L) |
Accessor function to a C-closure bound wxString on the C++ side. | |
Protected Attributes | |
wxEvtHandler * | m_poParent |
Pointer to the parent event handler (most often the parent window). | |
bool * | m_pbParentState |
Pointer to the state of the parent object (true == OK, false == not OK). | |
lua_State * | L |
Lua context. | |
wxString | m_strScript |
Lua script as a string in memory. | |
wxString | m_strDomain |
Lua "domain" name (the table where the functions are to register to). | |
bool | m_bOk |
... | |
Static Protected Attributes | |
static wxDynamicLibrary | m_oWxLuaScriptDynamicLibrary |
... | |
static t_luaL_newstate * | luaL_newstate = NULL |
static t_luaL_openlibs * | luaL_openlibs = NULL |
static t_lua_atpanic * | lua_atpanic = NULL |
static t_lua_error * | lua_error = NULL |
static t_lua_gettop * | lua_gettop = NULL |
static t_luaL_loadstring * | luaL_loadstring = NULL |
static t_lua_pushstring * | lua_pushstring = NULL |
static t_lua_pushinteger * | lua_pushinteger = NULL |
static t_lua_pushboolean * | lua_pushboolean = NULL |
static t_lua_tointeger * | lua_tointeger = NULL |
static t_lua_tolstring * | lua_tolstring = NULL |
static t_lua_tonumber * | lua_tonumber = NULL |
static t_lua_toboolean * | lua_toboolean = NULL |
static t_lua_isnumber * | lua_isnumber = NULL |
static t_lua_type * | lua_type = NULL |
static t_lua_isstring * | lua_isstring = NULL |
static t_lua_pushcclosure * | lua_pushcclosure = NULL |
static t_lua_call * | lua_call = NULL |
static t_lua_pcall * | lua_pcall = NULL |
static t_lua_cpcall * | lua_cpcall = NULL |
static t_lua_settable * | lua_settable = NULL |
static t_lua_setfield * | lua_setfield = NULL |
static t_lua_getfield * | lua_getfield = NULL |
static t_lua_settop * | lua_settop = NULL |
static t_lua_insert * | lua_insert = NULL |
static t_lua_pushvalue * | lua_pushvalue = NULL |
static t_lua_close * | lua_close = NULL |
static t_lua_createtable * | lua_createtable = NULL |
static t_lua_pushlightuserdata * | lua_pushlightuserdata = NULL |
static t_lua_topointer * | lua_topointer = NULL |
static t_lua_gettable * | lua_gettable = NULL |
static t_lua_pushnumber * | lua_pushnumber = NULL |
typedef lua_CFunction wxLuaScript::t_lua_atpanic(lua_State *, lua_CFunction) [protected] |
Definition at line 221 of file wxluascript.h.
typedef void wxLuaScript::t_lua_call(lua_State *, int, int) [protected] |
Definition at line 236 of file wxluascript.h.
typedef void wxLuaScript::t_lua_close(lua_State *) [protected] |
Definition at line 245 of file wxluascript.h.
typedef int wxLuaScript::t_lua_cpcall(lua_State *, lua_CFunction, void *) [protected] |
Definition at line 238 of file wxluascript.h.
typedef void wxLuaScript::t_lua_createtable(lua_State *, int, int) [protected] |
Definition at line 246 of file wxluascript.h.
typedef int wxLuaScript::t_lua_error(lua_State *) [protected] |
Definition at line 222 of file wxluascript.h.
typedef void wxLuaScript::t_lua_getfield(lua_State *, int, const char *) [protected] |
Definition at line 241 of file wxluascript.h.
typedef void wxLuaScript::t_lua_gettable(lua_State *, int) [protected] |
Definition at line 249 of file wxluascript.h.
typedef int wxLuaScript::t_lua_gettop(lua_State *) [protected] |
Definition at line 223 of file wxluascript.h.
typedef void wxLuaScript::t_lua_insert(lua_State *, int) [protected] |
Definition at line 243 of file wxluascript.h.
typedef int wxLuaScript::t_lua_isnumber(lua_State *, int) [protected] |
Definition at line 232 of file wxluascript.h.
typedef int wxLuaScript::t_lua_isstring(lua_State *, int) [protected] |
Definition at line 234 of file wxluascript.h.
typedef int wxLuaScript::t_lua_pcall(lua_State *, int, int, int) [protected] |
Definition at line 237 of file wxluascript.h.
typedef void wxLuaScript::t_lua_pushboolean(lua_State *, int) [protected] |
Definition at line 227 of file wxluascript.h.
typedef void wxLuaScript::t_lua_pushcclosure(lua_State *, lua_CFunction, int) [protected] |
Definition at line 235 of file wxluascript.h.
typedef void wxLuaScript::t_lua_pushinteger(lua_State *, lua_Integer) [protected] |
Definition at line 226 of file wxluascript.h.
typedef void wxLuaScript::t_lua_pushlightuserdata(lua_State *, void *) [protected] |
Definition at line 247 of file wxluascript.h.
typedef void wxLuaScript::t_lua_pushnumber(lua_State *, lua_Number) [protected] |
Definition at line 250 of file wxluascript.h.
typedef void wxLuaScript::t_lua_pushstring(lua_State *, const char *) [protected] |
Definition at line 225 of file wxluascript.h.
typedef void wxLuaScript::t_lua_pushvalue(lua_State *, int) [protected] |
Definition at line 244 of file wxluascript.h.
typedef void wxLuaScript::t_lua_setfield(lua_State *, int, const char *) [protected] |
Definition at line 240 of file wxluascript.h.
typedef void wxLuaScript::t_lua_settable(lua_State *, int) [protected] |
Definition at line 239 of file wxluascript.h.
typedef void wxLuaScript::t_lua_settop(lua_State *, int) [protected] |
Definition at line 242 of file wxluascript.h.
typedef int wxLuaScript::t_lua_toboolean(lua_State *, int) [protected] |
Definition at line 231 of file wxluascript.h.
typedef lua_Integer wxLuaScript::t_lua_tointeger(lua_State *, int) [protected] |
Definition at line 228 of file wxluascript.h.
typedef const char* wxLuaScript::t_lua_tolstring(lua_State *, int, size_t *) [protected] |
Definition at line 229 of file wxluascript.h.
typedef lua_Number wxLuaScript::t_lua_tonumber(lua_State *, int) [protected] |
Definition at line 230 of file wxluascript.h.
typedef const void* wxLuaScript::t_lua_topointer(lua_State *, int) [protected] |
Definition at line 248 of file wxluascript.h.
typedef int wxLuaScript::t_lua_type(lua_State *, int) [protected] |
Definition at line 233 of file wxluascript.h.
typedef int wxLuaScript::t_luaL_loadstring(lua_State *, const char *) [protected] |
Definition at line 224 of file wxluascript.h.
typedef lua_State* wxLuaScript::t_luaL_newstate() [protected] |
Definition at line 219 of file wxluascript.h.
typedef void wxLuaScript::t_luaL_openlibs(lua_State *) [protected] |
Definition at line 220 of file wxluascript.h.
wxLuaScript::wxLuaScript | ( | const wxString & | strScript = wxEmptyString , |
wxEvtHandler * | poParent = NULL , |
||
const wxString & | strDomain = wxEmptyString , |
||
bool * | pbParentState = NULL |
||
) |
Standard constructor.
strScript | The Lua source code of the script to execute. Default is the empty string. |
poParent | A pointer to the parent event handler (mostly a window), may be NULL |
strDomain | The name of the domain (the table name where to register the functions). Default is the empty string. |
pbParentState | A pointer to a boolean to get the error state, may be NULL |
Definition at line 67 of file wxluascript.cpp.
References WXLUASCRIPT_LIBLUA.
: m_bOk( true ) #endif // __WXLUASCRIPT_DYNAMIC__ { // Initialize members. m_strScript= strScript; m_poParent= poParent; m_strDomain= strDomain; m_pbParentState= pbParentState; if( m_pbParentState ) { (*m_pbParentState)= true; } #if __WXLUASCRIPT_DYNAMIC__ if( !m_oWxLuaScriptDynamicLibrary.IsLoaded() ) { if( m_oWxLuaScriptDynamicLibrary.Load( wxDynamicLibrary::CanonicalizeName( wxT( WXLUASCRIPT_LIBLUA ) ), wxDL_DEFAULT | wxDL_GLOBAL ) ) { luaL_newstate= (t_luaL_newstate *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "luaL_newstate" ) ); luaL_openlibs= (t_luaL_openlibs *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "luaL_openlibs" ) ); lua_atpanic= (t_lua_atpanic *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "lua_atpanic" ) ); lua_error= (t_lua_error *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "lua_error" ) ); lua_gettop= (t_lua_gettop *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "lua_gettop" ) ); luaL_loadstring= (t_luaL_loadstring *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "luaL_loadstring" ) ); lua_pushstring= (t_lua_pushstring *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "lua_pushstring" ) ); lua_pushinteger= (t_lua_pushinteger *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "lua_pushinteger" ) ); lua_pushboolean= (t_lua_pushboolean *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "lua_pushboolean" ) ); lua_tointeger= (t_lua_tointeger *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "lua_tointeger" ) ); lua_tolstring= (t_lua_tolstring *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "lua_tolstring" ) ); lua_tonumber= (t_lua_tonumber *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "lua_tonumber" ) ); lua_toboolean= (t_lua_toboolean *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "lua_toboolean" ) ); lua_isnumber= (t_lua_isnumber *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "lua_isnumber" ) ); lua_type= (t_lua_type *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "lua_type" ) ); lua_isstring= (t_lua_isstring *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "lua_isstring" ) ); lua_pushcclosure= (t_lua_pushcclosure *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "lua_pushcclosure" ) ); lua_call= (t_lua_call *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "lua_call" ) ); lua_pcall= (t_lua_pcall *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "lua_pcall" ) ); lua_cpcall= (t_lua_cpcall *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "lua_cpcall" ) ); lua_settable= (t_lua_settable *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "lua_settable" ) ); lua_setfield= (t_lua_setfield *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "lua_setfield" ) ); lua_getfield= (t_lua_getfield *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "lua_getfield" ) ); lua_settop= (t_lua_settop *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "lua_settop" ) ); lua_insert= (t_lua_insert *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "lua_insert" ) ); lua_pushvalue= (t_lua_pushvalue *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "lua_pushvalue" ) ); lua_close= (t_lua_close *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "lua_close" ) ); lua_createtable= (t_lua_createtable *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "lua_createtable" ) ); lua_pushlightuserdata= (t_lua_pushlightuserdata *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "lua_pushlightuserdata" ) ); lua_topointer= (t_lua_topointer *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "lua_topointer" ) ); lua_gettable= (t_lua_gettable *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "lua_gettable" ) ); lua_pushnumber= (t_lua_pushnumber *)m_oWxLuaScriptDynamicLibrary.GetSymbol( wxT( "lua_pushnumber" ) ); } else { // Remember the state; m_bOk= false; #if __DEBUG__ // Log waring message in DEBUG mode. wxLogWarning( wxString( wxT( "wxLuaScript::wxLuaScript -- " ) ) + _( "Cannot load Lua library." ) ); #endif // __DEBUG__ return; } } #endif // __WXLUASCRIPT_DYNAMIC__ // Initialize Lua. L= luaL_newstate(); // Load Lua base libraries. luaL_openlibs( L ); // Register an error handler (since there may be fatal Lua errors). lua_atpanic( L, LuaAtPanic ); // Register the this pointer (to the current wxLuaScript object) // as a global value called "this". lua_pushinteger( L, (long)this ); lua_setglobal( L, "this" ); // Register "SendMenuEvent" as Lua function. RegisterFunction( wxT( "SendMenuEvent" ), SendMenuEvent ); // Register "LogMessage" as Lua function. RegisterFunction( wxT( "LogMessage" ), LogMessage ); }
wxLuaScript::~wxLuaScript | ( | ) | [virtual] |
virtual void wxLuaScript::CallLuaFunction | ( | const wxString & | strLuaFunction | ) | [inline, virtual] |
Call a Lua function without return value (sometimes called a 'procedure') by given name.
strLuaFunction | the Lua function name to call |
Definition at line 132 of file wxluascript.h.
References L, lua_call, and lua_getfield.
{ lua_getfield( L, LUA_GLOBALSINDEX, strLuaFunction.char_str() ); lua_call( L, 0, 0 ); }
wxLuaScript * wxLuaScript::GetThis | ( | lua_State * | L | ) | [static, protected] |
Get the this-pointer from Lua.
L | a pointer to the Lua context. |
Definition at line 296 of file wxluascript.cpp.
References lua_tointeger.
Referenced by wxIScanLuaScript::CropImage(), wxIScanLuaScript::EnhenceColours(), wxIScanLuaScript::EnhenceOpticalContrast(), wxIScanLuaScript::Execute(), wxIScanLuaScript::Image2Grey(), wxIScanLuaScript::Image2Mono(), wxIScanLuaScript::OCR(), wxIScanLuaScript::OpenImage(), wxIScanLuaScript::ResetFileName(), wxIScanLuaScript::ResizeImage(), wxIScanLuaScript::RotateImage(), wxIScanLuaScript::RotateImage90(), Run(), wxIScanLuaScript::SaveImage(), and SendMenuEvent().
{ // Get the this-pointer from Lua. lua_getglobal( L, "this" ); return (wxLuaScript *)lua_tointeger( L, -1 ); }
bool wxLuaScript::IsOk | ( | ) | [inline] |
Returns the object state: true on OK and false otherwise.
Definition at line 212 of file wxluascript.h.
References m_bOk.
Referenced by wxIScanFrame::StartScript(), wxIScanLuaScript::wxIScanLuaScript(), and ~wxLuaScript().
int wxLuaScript::LogMessage | ( | lua_State * | L | ) | [static, protected] |
Log a message on the standard wxWidgets log target.
L | a pointer to the Lua context. |
Definition at line 383 of file wxluascript.cpp.
References lua_error, lua_gettop, lua_isstring, and lua_pushstring.
{ // Check the number of argument(s) and the type(s). if( ( lua_gettop( L ) != 1 ) || !lua_isstring( L, 1 ) ) { // Signal error. lua_pushstring( L, "Incorrect argument or incorrect number of arguments." ); lua_error( L ); } // Get the message and log it. wxLogMessage( wxString( (const char *)lua_tostring( L, 1 ), wxConvISO8859_1 ) ); // Return the number of (Lua) results. return 0; }
int wxLuaScript::LuaAtPanic | ( | lua_State * | L | ) | [static, protected] |
Error handler for (maybe fatal) Lua errors.
L | a pointer to the Lua context. |
Definition at line 369 of file wxluascript.cpp.
{ // Get the error message and log it. wxLogError( wxString( (const char *)lua_tostring( L, 1 ), wxConvISO8859_1 ) ); // Return the number of (Lua) results. return 0; }
int wxLuaScript::LuaBoolVarAccessor | ( | lua_State * | L | ) | [static, protected] |
Accessor function to a C-closure bound integer on the C/C++ side.
L | a pointer to the Lua context. |
Definition at line 230 of file wxluascript.cpp.
References lua_gettop, lua_pushboolean, lua_toboolean, and lua_topointer.
Referenced by RegisterVariable().
{ bool *p = (bool *)lua_topointer( L, lua_upvalueindex( 1 ) ); if( lua_gettop( L ) == 0 ) { // stack empty, so get lua_pushboolean( L, *p ); return 1; } else { // arg provided, so set *p = lua_toboolean( L, 1 ); return 0; } }
int wxLuaScript::LuaDoubleVarAccessor | ( | lua_State * | L | ) | [static, protected] |
Accessor function to a C-closure bound integer on the C/C++ side.
L | a pointer to the Lua context. |
Definition at line 254 of file wxluascript.cpp.
References lua_gettop, lua_pushnumber, lua_tonumber, and lua_topointer.
Referenced by RegisterVariable().
{ double *p = (double *)lua_topointer( L, lua_upvalueindex( 1 ) ); if( lua_gettop( L ) == 0 ) { // stack empty, so get lua_pushnumber( L, *p ); return 1; } else { // arg provided, so set *p = (double)lua_tonumber( L, 1 ); return 0; } }
int wxLuaScript::LuaIntVarAccessor | ( | lua_State * | L | ) | [static, protected] |
Accessor function to a C-closure bound integer on the C/C++ side.
L | a pointer to the Lua context. |
Definition at line 206 of file wxluascript.cpp.
References lua_gettop, lua_pushinteger, lua_tointeger, and lua_topointer.
Referenced by RegisterVariable().
{ int *p = (int *)lua_topointer( L, lua_upvalueindex( 1 ) ); if( lua_gettop( L ) == 0 ) { // stack empty, so get lua_pushinteger( L, *p ); return 1; } else { // arg provided, so set *p = lua_tointeger( L, 1 ); return 0; } }
int wxLuaScript::LuaStringVarAccessor | ( | lua_State * | L | ) | [static, protected] |
Accessor function to a C-closure bound wxString on the C++ side.
L | a pointer to the Lua context. |
Definition at line 278 of file wxluascript.cpp.
References lua_gettop, lua_pushstring, and lua_topointer.
Referenced by RegisterVariable().
{ wxString *p = (wxString *)lua_topointer( L, lua_upvalueindex( 1 ) ); if( lua_gettop( L ) == 0 ) { // stack empty, so get lua_pushstring( L, p->char_str( wxConvISO8859_1 ) ); return 1; } else { // arg provided, so set (*p)= wxString( lua_tostring( L, 1 ), wxConvISO8859_1 ); return 0; } }
virtual void wxLuaScript::RegisterConstant | ( | const wxString & | strLuaConstantName, |
const int | nValue | ||
) | [inline, virtual] |
Register an integer constant to Lua.
strLuaConstantName | the constant's name in Lua |
nValue | the constant's value as integer |
Definition at line 98 of file wxluascript.h.
References L, lua_pushinteger, lua_pushstring, and lua_settable.
{ lua_pushstring( L, strLuaConstantName.char_str() ); lua_pushinteger( L, nValue ); lua_settable( L, LUA_GLOBALSINDEX ); }
virtual void wxLuaScript::RegisterConstant | ( | const wxString & | strLuaConstantName, |
const wxString & | strValue | ||
) | [inline, virtual] |
Register a string constant to Lua.
strLuaConstantName | the constant's name in Lua |
strValue | the constant's value as string |
Definition at line 87 of file wxluascript.h.
References L, lua_pushstring, and lua_settable.
Referenced by wxIScanFrame::StartScript().
{ lua_pushstring( L, strLuaConstantName.char_str() ); lua_pushstring( L, strValue.char_str() ); lua_settable( L, LUA_GLOBALSINDEX ); }
void wxLuaScript::RegisterFunction | ( | lua_State * | L, |
const char * | pszTableName, | ||
const char * | pszFuncName, | ||
lua_CFunction | pLuaCFunction | ||
) | [static, protected] |
Register a new (LuaC-)function to Lua. Lower level function.
L | a pointer to the Lua context. |
pszTableName | the table name where the function is assigned to (a kind of domain) |
pszFuncName | the name of the C function |
pLuaCFunction | a pointer to the C function |
Definition at line 175 of file wxluascript.cpp.
References lua_createtable, lua_getfield, lua_pushstring, lua_setfield, and lua_settable.
{ lua_getfield( L, LUA_GLOBALSINDEX, pszTableName ); // push table onto stack if( !lua_istable( L, -1 ) ) // not a table, create it { lua_createtable( L, 0, 1 ); // create new table lua_setfield( L, LUA_GLOBALSINDEX, pszTableName) ; // add it to global context // reset table on stack: lua_pop( L, 1 ); // pop table (nil value) from stack lua_getfield( L, LUA_GLOBALSINDEX, pszTableName ); // push table onto stack } lua_pushstring( L, pszFuncName ); // push key onto stack lua_pushcfunction( L, pLuaCFunction ); // push value onto stack lua_settable( L, -3 ); // add key-value pair to table lua_pop( L, 1 ); // pop table from stack }
virtual void wxLuaScript::RegisterFunction | ( | const wxString & | strLuaCFunctionName, |
lua_CFunction | pLuaCFunction | ||
) | [inline, virtual] |
Register a new (LuaC-)function to Lua.
strLuaCFunctionName | the function's name in Lua |
pLuaCFunction | a pointer to the LuaC-function |
Definition at line 71 of file wxluascript.h.
References L, and m_strDomain.
Referenced by wxIScanLuaScript::wxIScanLuaScript().
{ if( m_strDomain.IsEmpty() ) { lua_register( L, strLuaCFunctionName.char_str(), pLuaCFunction ); } else { RegisterFunction( L, m_strDomain.char_str(), strLuaCFunctionName.char_str(), pLuaCFunction ); } }
void wxLuaScript::RegisterVariable | ( | const wxString & | strLuaVarName, |
const double * | pnValue | ||
) | [virtual] |
Register a double variable to Lua.
strLuaVarName | the variable's name in Lua |
pnValue | a pointer to the double variable |
Definition at line 246 of file wxluascript.cpp.
References L, lua_gettable, lua_pushcclosure, lua_pushlightuserdata, lua_setfield, and LuaDoubleVarAccessor().
{ lua_gettable( L, LUA_GLOBALSINDEX ); lua_pushlightuserdata( L, (void *)pnValue ); lua_pushcclosure( L, wxLuaScript::LuaDoubleVarAccessor, 1 ); lua_setfield( L, LUA_GLOBALSINDEX, strLuaVarName.char_str() ); }
void wxLuaScript::RegisterVariable | ( | const wxString & | strLuaVarName, |
const int * | pnValue | ||
) | [virtual] |
Register an integer variable to Lua.
strLuaVarName | the variable's name in Lua |
pnValue | a pointer to the integer variable |
Definition at line 198 of file wxluascript.cpp.
References L, lua_gettable, lua_pushcclosure, lua_pushlightuserdata, lua_setfield, and LuaIntVarAccessor().
Referenced by wxIScanFrame::StartScript().
{ lua_gettable( L, LUA_GLOBALSINDEX ); lua_pushlightuserdata( L, (void *)pnValue ); lua_pushcclosure( L, wxLuaScript::LuaIntVarAccessor, 1 ); lua_setfield( L, LUA_GLOBALSINDEX, strLuaVarName.char_str() ); }
void wxLuaScript::RegisterVariable | ( | const wxString & | strLuaVarName, |
const wxString * | pstrValue | ||
) | [virtual] |
Register a wxString variable to Lua.
strLuaVarName | the variable's name in Lua |
pstrValue | a pointer to the string variable |
Definition at line 270 of file wxluascript.cpp.
References L, lua_gettable, lua_pushcclosure, lua_pushlightuserdata, lua_setfield, and LuaStringVarAccessor().
{ lua_gettable( L, LUA_GLOBALSINDEX ); lua_pushlightuserdata( L, (void *)pstrValue ); lua_pushcclosure( L, wxLuaScript::LuaStringVarAccessor, 1 ); lua_setfield( L, LUA_GLOBALSINDEX, strLuaVarName.char_str() ); }
void wxLuaScript::RegisterVariable | ( | const wxString & | strLuaVarName, |
const bool * | pnValue | ||
) | [virtual] |
Register a boolean variable to Lua.
strLuaVarName | the variable's name in Lua |
pnValue | a pointer to the boolean variable |
Definition at line 222 of file wxluascript.cpp.
References L, lua_gettable, lua_pushcclosure, lua_pushlightuserdata, lua_setfield, and LuaBoolVarAccessor().
{ lua_gettable( L, LUA_GLOBALSINDEX ); lua_pushlightuserdata( L, (void *)pnValue ); lua_pushcclosure( L, wxLuaScript::LuaBoolVarAccessor, 1 ); lua_setfield( L, LUA_GLOBALSINDEX, strLuaVarName.char_str() ); }
virtual void wxLuaScript::Run | ( | ) | [inline, virtual] |
Run the Lua script in memory.
Definition at line 61 of file wxluascript.h.
References L, and lua_cpcall.
Referenced by wxIScanFrame::StartScript().
{ // Run the script. lua_cpcall( L, wxLuaScript::Run, NULL ); }
int wxLuaScript::Run | ( | lua_State * | L | ) | [static, protected] |
Run the Lua script in memory in protected mode.
L | a pointer to the Lua context. |
Definition at line 308 of file wxluascript.cpp.
References GetThis(), lua_gettop, lua_insert, lua_pcall, luaL_loadstring, m_strScript, and TraceBack().
{ // Get the this-pointer to the current wxLuaScript object. wxLuaScript *poThis= GetThis( L ); if( luaL_loadstring( L, poThis->m_strScript.char_str() ) ) { // Log an error message. wxLogError( wxString( wxT( "int wxLuaScript::Run( lua_State* L ) -- " ) ) + _( "Cannot initialize Lua script." ) ); // Return the number of (Lua) results. return 0; } // Insert TraceBack function. int base= lua_gettop(L); /* function index */ lua_pushcfunction( L, wxLuaScript::TraceBack ); /* push traceback function */ lua_insert( L, base ); /* put it under chunk and args */ // Run the script (from memory) and output an error // message if there was an error running the script. if( lua_pcall( L, 0, 0, base ) && !lua_isnil( L, -1 ) ) { // Get the error message and log it. wxLogError( wxString( (const char *)lua_tostring( L, -1 ), wxConvISO8859_1 ) ); } // Return the number of (Lua) results. return 0; }
int wxLuaScript::SendMenuEvent | ( | lua_State * | L | ) | [static, protected] |
Send a menu event to the parent event handler.
L | a pointer to the Lua context. |
Definition at line 402 of file wxluascript.cpp.
References GetThis(), lua_error, lua_gettop, lua_isnumber, lua_pushboolean, lua_pushstring, lua_tonumber, m_pbParentState, and m_poParent.
{ // Check the number of (Lua) argument(s) and the type(s). if( ( lua_gettop( L ) != 1 ) || !lua_isnumber( L, 1 ) ) { // Signal error. lua_pushstring( L, "Incorrect argument or incorrect number of arguments." ); lua_error( L ); } // Get the this pointer to the current wxLuaScript object. wxLuaScript *poThis= GetThis( L ); // Get the pointer to the event handler. wxEvtHandler *poParent= poThis->m_poParent; // Post the message (if possible). if( poParent ) { // Process the corresponding wxWidgets menu event. // // NOTE: We get the adress of the this-pointer from Lua // (for this is a static function, and we need it // to call the correct event handler). wxCommandEvent oEvent( wxEVT_COMMAND_MENU_SELECTED, lua_tonumber( L, 1 ) ); if( poParent->ProcessEvent( oEvent ) ) { // Push the return value ( the parent state ); if( poThis->m_pbParentState ) { lua_pushboolean( L, *poThis->m_pbParentState ); (*poThis->m_pbParentState)= true; } else { lua_pushboolean( L, true ); } } else { // Push an error value for the event could not be handled // or a proper event handler could not be found. #if __DEBUG__ wxLogWarning( wxT( "wxLuaScript::SendMenuEvent -- Could not handle the event." ) ); #endif lua_pushboolean( L, false ); } } else { // Push an error value for there is no parent to post the // message. lua_pushboolean( L, false ); } // Return the number of (Lua) results. return 1; }
int wxLuaScript::TraceBack | ( | lua_State * | L | ) | [static, protected] |
Create a stack trace on the Lua stack.
L | a pointer to the Lua context. |
Definition at line 343 of file wxluascript.cpp.
References lua_call, lua_getfield, lua_isstring, lua_pushinteger, and lua_pushvalue.
Referenced by Run().
{ if( !lua_isstring(L, 1) ) /* 'message' not a string? */ { return 1; /* keep it intact */ } lua_getfield(L, LUA_GLOBALSINDEX, "debug"); if( !lua_istable( L, -1 ) ) { lua_pop( L, 1 ); return 1; } lua_getfield( L, -1, "traceback" ); if( !lua_isfunction( L, -1 ) ) { lua_pop( L, 2 ); return 1; } lua_pushvalue( L, 1 ); /* pass error message */ lua_pushinteger( L, 2 ); /* skip this function and traceback */ lua_call( L, 2, 1 ); /* call debug.traceback */ return 1; }
lua_State* wxLuaScript::L [protected] |
Lua context.
Definition at line 206 of file wxluascript.h.
Referenced by CallLuaFunction(), RegisterConstant(), RegisterFunction(), RegisterVariable(), Run(), and ~wxLuaScript().
wxLuaScript::t_lua_atpanic * wxLuaScript::lua_atpanic = NULL [static, protected] |
Definition at line 254 of file wxluascript.h.
wxLuaScript::t_lua_call * wxLuaScript::lua_call = NULL [static, protected] |
Definition at line 269 of file wxluascript.h.
Referenced by CallLuaFunction(), and TraceBack().
wxLuaScript::t_lua_close * wxLuaScript::lua_close = NULL [static, protected] |
Definition at line 278 of file wxluascript.h.
Referenced by ~wxLuaScript().
wxLuaScript::t_lua_cpcall * wxLuaScript::lua_cpcall = NULL [static, protected] |
Definition at line 271 of file wxluascript.h.
Referenced by Run().
wxLuaScript::t_lua_createtable * wxLuaScript::lua_createtable = NULL [static, protected] |
Definition at line 279 of file wxluascript.h.
Referenced by RegisterFunction().
wxLuaScript::t_lua_error * wxLuaScript::lua_error = NULL [static, protected] |
Definition at line 255 of file wxluascript.h.
Referenced by wxIScanLuaScript::CopyText2Clipboard(), wxIScanLuaScript::CropImage(), wxIScanLuaScript::EnhenceColours(), wxIScanLuaScript::EnhenceOpticalContrast(), wxIScanLuaScript::Execute(), wxIScanLuaScript::Image2Grey(), wxIScanLuaScript::Image2Mono(), LogMessage(), wxIScanLuaScript::OCR(), wxIScanLuaScript::OpenImage(), wxIScanLuaScript::ResetFileName(), wxIScanLuaScript::ResizeImage(), wxIScanLuaScript::RotateImage(), wxIScanLuaScript::RotateImage90(), wxIScanLuaScript::SaveImage(), and SendMenuEvent().
wxLuaScript::t_lua_getfield * wxLuaScript::lua_getfield = NULL [static, protected] |
Definition at line 274 of file wxluascript.h.
Referenced by CallLuaFunction(), RegisterFunction(), and TraceBack().
wxLuaScript::t_lua_gettable * wxLuaScript::lua_gettable = NULL [static, protected] |
Definition at line 282 of file wxluascript.h.
Referenced by RegisterVariable().
wxLuaScript::t_lua_gettop * wxLuaScript::lua_gettop = NULL [static, protected] |
Definition at line 256 of file wxluascript.h.
Referenced by wxIScanLuaScript::CopyText2Clipboard(), wxIScanLuaScript::CropImage(), wxIScanLuaScript::EnhenceColours(), wxIScanLuaScript::EnhenceOpticalContrast(), wxIScanLuaScript::Execute(), wxIScanLuaScript::Image2Grey(), wxIScanLuaScript::Image2Mono(), LogMessage(), LuaBoolVarAccessor(), LuaDoubleVarAccessor(), LuaIntVarAccessor(), LuaStringVarAccessor(), wxIScanLuaScript::OCR(), wxIScanLuaScript::OpenImage(), wxIScanLuaScript::ResetFileName(), wxIScanLuaScript::ResizeImage(), wxIScanLuaScript::RotateImage(), wxIScanLuaScript::RotateImage90(), Run(), wxIScanLuaScript::SaveImage(), and SendMenuEvent().
wxLuaScript::t_lua_insert * wxLuaScript::lua_insert = NULL [static, protected] |
Definition at line 276 of file wxluascript.h.
Referenced by Run().
wxLuaScript::t_lua_isnumber * wxLuaScript::lua_isnumber = NULL [static, protected] |
Definition at line 265 of file wxluascript.h.
Referenced by wxIScanLuaScript::CropImage(), wxIScanLuaScript::EnhenceColours(), wxIScanLuaScript::Image2Mono(), wxIScanLuaScript::ResizeImage(), wxIScanLuaScript::RotateImage(), and SendMenuEvent().
wxLuaScript::t_lua_isstring * wxLuaScript::lua_isstring = NULL [static, protected] |
Definition at line 267 of file wxluascript.h.
Referenced by wxIScanLuaScript::CopyText2Clipboard(), wxIScanLuaScript::Execute(), LogMessage(), wxIScanLuaScript::OpenImage(), wxIScanLuaScript::SaveImage(), and TraceBack().
wxLuaScript::t_lua_pcall * wxLuaScript::lua_pcall = NULL [static, protected] |
Definition at line 270 of file wxluascript.h.
Referenced by Run().
wxLuaScript::t_lua_pushboolean * wxLuaScript::lua_pushboolean = NULL [static, protected] |
Definition at line 260 of file wxluascript.h.
Referenced by wxIScanLuaScript::CopyText2Clipboard(), wxIScanLuaScript::Execute(), LuaBoolVarAccessor(), wxIScanLuaScript::OpenImage(), wxIScanLuaScript::SaveImage(), and SendMenuEvent().
wxLuaScript::t_lua_pushcclosure * wxLuaScript::lua_pushcclosure = NULL [static, protected] |
Definition at line 268 of file wxluascript.h.
Referenced by RegisterVariable().
wxLuaScript::t_lua_pushinteger * wxLuaScript::lua_pushinteger = NULL [static, protected] |
Definition at line 259 of file wxluascript.h.
Referenced by LuaIntVarAccessor(), RegisterConstant(), and TraceBack().
wxLuaScript::t_lua_pushlightuserdata * wxLuaScript::lua_pushlightuserdata = NULL [static, protected] |
Definition at line 280 of file wxluascript.h.
Referenced by RegisterVariable().
wxLuaScript::t_lua_pushnumber * wxLuaScript::lua_pushnumber = NULL [static, protected] |
Definition at line 283 of file wxluascript.h.
Referenced by LuaDoubleVarAccessor().
wxLuaScript::t_lua_pushstring * wxLuaScript::lua_pushstring = NULL [static, protected] |
Definition at line 258 of file wxluascript.h.
Referenced by wxIScanLuaScript::CopyText2Clipboard(), wxIScanLuaScript::CropImage(), wxIScanLuaScript::EnhenceColours(), wxIScanLuaScript::EnhenceOpticalContrast(), wxIScanLuaScript::Execute(), wxIScanLuaScript::Image2Grey(), wxIScanLuaScript::Image2Mono(), LogMessage(), LuaStringVarAccessor(), wxIScanLuaScript::OCR(), wxIScanLuaScript::OpenImage(), RegisterConstant(), RegisterFunction(), wxIScanLuaScript::ResetFileName(), wxIScanLuaScript::ResizeImage(), wxIScanLuaScript::RotateImage(), wxIScanLuaScript::RotateImage90(), wxIScanLuaScript::SaveImage(), and SendMenuEvent().
wxLuaScript::t_lua_pushvalue * wxLuaScript::lua_pushvalue = NULL [static, protected] |
Definition at line 277 of file wxluascript.h.
Referenced by TraceBack().
wxLuaScript::t_lua_setfield * wxLuaScript::lua_setfield = NULL [static, protected] |
Definition at line 273 of file wxluascript.h.
Referenced by RegisterFunction(), and RegisterVariable().
wxLuaScript::t_lua_settable * wxLuaScript::lua_settable = NULL [static, protected] |
Definition at line 272 of file wxluascript.h.
Referenced by RegisterConstant(), and RegisterFunction().
wxLuaScript::t_lua_settop * wxLuaScript::lua_settop = NULL [static, protected] |
Definition at line 275 of file wxluascript.h.
wxLuaScript::t_lua_toboolean * wxLuaScript::lua_toboolean = NULL [static, protected] |
Definition at line 264 of file wxluascript.h.
Referenced by wxIScanLuaScript::Execute(), LuaBoolVarAccessor(), wxIScanLuaScript::OCR(), wxIScanLuaScript::OpenImage(), and wxIScanLuaScript::RotateImage90().
wxLuaScript::t_lua_tointeger * wxLuaScript::lua_tointeger = NULL [static, protected] |
Definition at line 261 of file wxluascript.h.
Referenced by wxIScanLuaScript::CropImage(), wxIScanLuaScript::EnhenceColours(), GetThis(), wxIScanLuaScript::Image2Mono(), LuaIntVarAccessor(), and wxIScanLuaScript::ResizeImage().
wxLuaScript::t_lua_tolstring * wxLuaScript::lua_tolstring = NULL [static, protected] |
Definition at line 262 of file wxluascript.h.
wxLuaScript::t_lua_tonumber * wxLuaScript::lua_tonumber = NULL [static, protected] |
Definition at line 263 of file wxluascript.h.
Referenced by LuaDoubleVarAccessor(), wxIScanLuaScript::ResizeImage(), wxIScanLuaScript::RotateImage(), and SendMenuEvent().
wxLuaScript::t_lua_topointer * wxLuaScript::lua_topointer = NULL [static, protected] |
Definition at line 281 of file wxluascript.h.
Referenced by LuaBoolVarAccessor(), LuaDoubleVarAccessor(), LuaIntVarAccessor(), and LuaStringVarAccessor().
wxLuaScript::t_lua_type * wxLuaScript::lua_type = NULL [static, protected] |
Definition at line 266 of file wxluascript.h.
wxLuaScript::t_luaL_loadstring * wxLuaScript::luaL_loadstring = NULL [static, protected] |
Definition at line 257 of file wxluascript.h.
Referenced by Run().
wxLuaScript::t_luaL_newstate * wxLuaScript::luaL_newstate = NULL [static, protected] |
Definition at line 252 of file wxluascript.h.
wxLuaScript::t_luaL_openlibs * wxLuaScript::luaL_openlibs = NULL [static, protected] |
Definition at line 253 of file wxluascript.h.
bool wxLuaScript::m_bOk [protected] |
wxDynamicLibrary wxLuaScript::m_oWxLuaScriptDynamicLibrary [static, protected] |
...
Definition at line 215 of file wxluascript.h.
bool* wxLuaScript::m_pbParentState [protected] |
Pointer to the state of the parent object (true == OK, false == not OK).
Definition at line 205 of file wxluascript.h.
Referenced by SendMenuEvent().
wxEvtHandler* wxLuaScript::m_poParent [protected] |
Pointer to the parent event handler (most often the parent window).
Definition at line 204 of file wxluascript.h.
Referenced by wxIScanLuaScript::CropImage(), wxIScanLuaScript::EnhenceColours(), wxIScanLuaScript::EnhenceOpticalContrast(), wxIScanLuaScript::Execute(), wxIScanLuaScript::Image2Grey(), wxIScanLuaScript::Image2Mono(), wxIScanLuaScript::OCR(), wxIScanLuaScript::OpenImage(), wxIScanLuaScript::ResetFileName(), wxIScanLuaScript::ResizeImage(), wxIScanLuaScript::RotateImage(), wxIScanLuaScript::RotateImage90(), wxIScanLuaScript::SaveImage(), and SendMenuEvent().
wxString wxLuaScript::m_strDomain [protected] |
Lua "domain" name (the table where the functions are to register to).
Definition at line 208 of file wxluascript.h.
Referenced by RegisterFunction().
wxString wxLuaScript::m_strScript [protected] |
Lua script as a string in memory.
Definition at line 207 of file wxluascript.h.
Referenced by Run().