From: John L. <jr...@us...> - 2008-01-15 01:04:09
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/include In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv3556/wxLua/modules/wxlua/include Modified Files: wxlstate.h Log Message: * Changed wxLuaState_Type enum for wxLuaState(lua_State*, wxLuaState_Type) Removed wxLUASTATE_USESTATE and you now | together wxLUASTATE_SETSTATE with wxLUASTATE_OPENBINDINGS if you want the bindings opened. Cleans up the creation of the wxLuaState so a precreated lua_State should be able to be used easier. - Remove poorly named wxLuaState::LuaError() and CheckRunError() and replaced them with the C functions wxlua_errorinfo() and wxlua_LUA_ERR_msg() respectively. - Added wxlua_pushargs(wxChar**, int) for a standard way to push args into Lua. - Copy Lua's print() function to print_lua() instead of simply overwriting it in case someone really wants to use it. Index: wxlstate.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/include/wxlstate.h,v retrieving revision 1.114 retrieving revision 1.115 diff -C2 -d -r1.114 -r1.115 *** wxlstate.h 5 Jan 2008 00:15:45 -0000 1.114 --- wxlstate.h 15 Jan 2008 01:04:04 -0000 1.115 *************** *** 187,197 **** // ---------------------------------------------------------------------------- ! // The functions below are Lua C helper functions that are also part of the wxLuaState // and you are recommended to use those if the wxLuaState is required. However // in some cases it may not be necessary to create a wxLuaState and just // calling these functions will suffice. Only the functions that do not ! // require the internal data from the wxLuaState are separated here // ---------------------------------------------------------------------------- // Push the errorMsg on the stack and call luaL_error() WXDLLIMPEXP_WXLUA void LUACALL wxlua_error(lua_State* L, const char* errorMsg); --- 187,211 ---- // ---------------------------------------------------------------------------- ! // The functions below are Lua C helper functions, some are also part of the wxLuaState // and you are recommended to use those if the wxLuaState is required. However // in some cases it may not be necessary to create a wxLuaState and just // calling these functions will suffice. Only the functions that do not ! // require the internal data from the wxLuaState are separated here. // ---------------------------------------------------------------------------- + // Translate the LUA_ERRXXX integers into a human readable string. + // returns an empty string for an input of 0. + WXDLLIMPEXP_WXLUA wxString wxlua_LUA_ERR_msg(int LUA_ERRx); + + // Get information from the return value of lua_pcall(), luaL_loadbuffer(), etc + // and builds an errMsg with wxlua_LUA_ERR_msg() and if the current top + // is > than top it tries to get Lua's error string from the top of the stack. + // Returns true if status != 0 and the errMsg and line_num are filled. + // If errMsg and line_num aren't null then fill them with the msg and line. + // status is the return from lua_pcall(), luaL_loadbuffer(), etc, LUA_ERRxxx + // top is the lua_gettop from before the call that may have generated the error. + WXDLLIMPEXP_WXLUA bool wxlua_errorinfo(lua_State* L, int status, int top, wxString* errMsg = NULL, int* line_num = NULL); + + // Push the errorMsg on the stack and call luaL_error() WXDLLIMPEXP_WXLUA void LUACALL wxlua_error(lua_State* L, const char* errorMsg); *************** *** 500,503 **** --- 514,523 ---- WXDLLIMPEXP_WXLUA wxString wxlua_concatwxArrayString(const wxArrayString& arr, const wxString& sep = wxT("\n")); + + // Push the program args into a global table called "args" as the lua executable does. + // start_n is the arg to start pushing until max args "argc". + // returns the number of args pushed. + WXDLLIMPEXP_WXLUA int wxlua_pushargs(lua_State* L, wxChar **argv, int argc, int start_n); + //---------------------------------------------------------------------------- // Derived class member functions for classes in wxLua. The data is stored *************** *** 632,645 **** //---------------------------------------------------------------------------- ! enum wxLuaState_Type { wxLUASTATE_GETSTATE = 1, // Attach to a previously created wxLuaState's // lua_State refing the existing wxLuaStateRefData - wxLUASTATE_USESTATE = 2, // Set the lua_State and register the bindings. - wxLUASTATE_SETSTATE = 3, // Set the lua_State, but don't register the bindings. ! wxLUASTATE_STATICSTATE = 0x1000 // The lua_State is static and the wxLuaState ! // will not lua_close() it when Destroy()ed. ! // Use with wxLUASTATE_USESTATE/SETSTATE only. }; --- 652,672 ---- //---------------------------------------------------------------------------- ! // enum wxLuaState_Type is for the function ! // wxLuaState::Create(lua_State* L, int state_type = wxLUASTATE_GETSTATE); ! enum wxLuaState_Type { wxLUASTATE_GETSTATE = 1, // Attach to a previously created wxLuaState's // lua_State refing the existing wxLuaStateRefData ! wxLUASTATE_SETSTATE = 2, // Set the lua_State for the wxLuaState. ! // Does not call lua_openlibs() so you should have ! // called before setting it to the wxLuaState. ! ! // The values below are to be ored with wxLUASTATE_SETSTATE only. ! wxLUASTATE_STATICSTATE = 0x10, // The lua_State is static and the wxLuaState ! // will not lua_close() it when Destroy()ed. ! wxLUASTATE_OPENBINDINGS = 0x20, // Install all the bindings in ! // wxLuaBinding::GetBindingList() into the ! // lua_State. }; *************** *** 650,661 **** { public: ! // Default constructor or if create=true then create a new lua_State ! // and add all the bindings in wxLuaBinding::GetBindingList() wxLuaState(bool create = false) { if (create) Create(); } ! // Create a new lua_State, add the bindings in wxLuaBinding::GetBindingList() ! // sets the wxEvtHandler and wxWindowID to send the wxLuaEvents to. wxLuaState(wxEvtHandler *handler, wxWindowID id = wxID_ANY) { Create(handler, id); } // Create a wxLuaState from an existing lua_State. ! // state_type is enum wxLuaState_Type. inline wxLuaState(lua_State* L, int state_type = wxLUASTATE_GETSTATE) { Create(L, state_type); } // Copy constructor, refs existing wxLuaState --- 677,688 ---- { public: ! // Default constructor or if create=true then ! // call the function Create(wxEvtHandler=NULL, id=wxID_ANY). wxLuaState(bool create = false) { if (create) Create(); } ! // Create a new lua_State and add the bindings. ! // Calls the function Create(wxEvtHandler, id). wxLuaState(wxEvtHandler *handler, wxWindowID id = wxID_ANY) { Create(handler, id); } // Create a wxLuaState from an existing lua_State. ! // Calls the function Create(lua_State, state_type), state_type is enum wxLuaState_Type. inline wxLuaState(lua_State* L, int state_type = wxLUASTATE_GETSTATE) { Create(L, state_type); } // Copy constructor, refs existing wxLuaState *************** *** 670,678 **** // Ref the given wxLuaState void Create(const wxLuaState& wxlState); ! // Create a new lua_State and send events to this handler. // The handler may be NULL to not send events to anyone. bool Create(wxEvtHandler *handler = NULL, wxWindowID id = wxID_ANY); // Create a wxLuaState from an existing lua_State. ! // state_type is enum wxLuaState_Type. bool Create(lua_State* L, int state_type = wxLUASTATE_GETSTATE); --- 697,706 ---- // Ref the given wxLuaState void Create(const wxLuaState& wxlState); ! // Create a new lua_State and send wxLuaEvents to this handler. // The handler may be NULL to not send events to anyone. + // Calls the function Create(lua_State, wxLUASTATE_USESTATE). bool Create(wxEvtHandler *handler = NULL, wxWindowID id = wxID_ANY); // Create a wxLuaState from an existing lua_State. ! // See enum wxLuaState_Type for infomation about state_type. bool Create(lua_State* L, int state_type = wxLUASTATE_GETSTATE); *************** *** 699,705 **** // created without the wxLUASTATE_STATICSTATE flag. bool CloseLuaState(bool force); ! // Are we currently being closed? Used when the garbage collector is running, but ! // we don't care about cleaning Lua up so just delete the data ! // (internal use) bool IsClosing() const; --- 727,732 ---- // created without the wxLUASTATE_STATICSTATE flag. bool CloseLuaState(bool force); ! // Are we currently being closed? Used when the garbage collector is running when ! // we don't care about cleaning Lua up so just delete the data. (internal use) bool IsClosing() const; *************** *** 743,785 **** // ----------------------------------------------------------------------- ! // Run a Lua file from disk using lua_loadfile, returns Lua's error code int RunFile(const wxString &fileName); ! // Run a string that contains Lua code using luaL_loadbuffer, returns Lua's error code int RunString(const wxString &script, const wxString& name = wxEmptyString); // Run a char array #included from bin2c compilation or something else ! // using luaL_loadbuffer, returns Lua's error code int RunBuffer(const unsigned char buf[], size_t size, const wxString &name = wxT("= lua")); // Is a program running now, running state is set for Run/File/String/Buffer bool IsRunning() const; ! // Replacement for lua_pcall that sends a wxEVT_LUA_ERROR on error // narg is the number of args to the function to call. ! // nresults is the number of values returned which Lua will adjust to match ! // use LUA_MULTRET for nresults to leave all of them on the stack int LuaPCall(int narg, int nresults); - int LuaDoString(const wxString &script, const wxString& name = wxEmptyString) { return RunString(script, name); } - int LuaDoFile(const wxString &filename) { return RunFile(filename); } - int LuaDoBuffer(const char *buffer, size_t len, const char *name) { return RunBuffer((const unsigned char*)buffer, len, lua2wx(name)); } ! // Try to compile the Lua program. Creates new lua_State to test for syntax ! // errors and sends error events. See wxLuaState::LuaError() for errMsg and line_num. ! int CompileString(const wxString &script, const wxString& name = wxEmptyString, ! wxString* errMsg_ = NULL, int* line_num = NULL); ! int CompileBuffer(const unsigned char buf[], size_t size, const wxString &name = wxEmptyString, ! wxString* errMsg_ = NULL, int* line_num = NULL); ! ! // Checks the status with CheckRunError() and tries to get Lua's error string ! // from the top of the stack and sends a wxEVT_LUA_ERROR. ! // If the lua_State is NULL then use the internal one from this class. ! // If errMsg and line_num aren't null then fill them with the msg and line. ! // this info is the same as in the error event. ! // top is the lua_gettop from before the call that may have generated the error ! // see usage in RunBuffer ! int LuaError(int status, int top, lua_State* L = NULL, wxString* errMsg_ = NULL, int* line_num = NULL); ! // Check the return value of LuaDoFile, LuaDoBuffer, lua_dostring, lua_dofile ! // returns true for no error, if error fills msg with a useful message if !NULL ! // only translates the status from LUA_ERRXXX to a human readable string ! static bool CheckRunError(int status, wxString *msg); // Get the wxEventType that Lua may currently be in, wxEVT_NULL if not in an --- 770,805 ---- // ----------------------------------------------------------------------- ! // Run a Lua file from disk using lua_loadfile() then LuaPCall(). ! // Returns 0 on success or Lua's error code. ! // Sends a wxEVT_LUA_ERROR wxLuaEvent on error. int RunFile(const wxString &fileName); ! // Run a string that contains Lua code using luaL_loadbuffer() then LuaPCall(). ! // Returns 0 on success or Lua's error code. ! // Sends a wxEVT_LUA_ERROR wxLuaEvent on error. int RunString(const wxString &script, const wxString& name = wxEmptyString); // Run a char array #included from bin2c compilation or something else ! // using luaL_loadbuffer() then LuaPCall(). ! // Returns 0 on success or Lua's error code. ! // Sends a wxEVT_LUA_ERROR wxLuaEvent on error. int RunBuffer(const unsigned char buf[], size_t size, const wxString &name = wxT("= lua")); + int LuaDoString(const wxString &script, const wxString& name = wxEmptyString) { return RunString(script, name); } + int LuaDoFile(const wxString &filename) { return RunFile(filename); } + int LuaDoBuffer(const char *buffer, size_t len, const char *name) { return RunBuffer((const unsigned char*)buffer, len, lua2wx(name)); } + // Is a program running now, running state is set for Run/File/String/Buffer bool IsRunning() const; ! // Replacement for lua_pcall(), leaves nothing on the stack even on error. ! // Returns 0 on success or Lua's error code. ! // Sends a wxEVT_LUA_ERROR wxLuaEvent on error. // narg is the number of args to the function to call. ! // nresults is the number of values expected to be returned and Lua ! // will adjust the stack to match. ! // Use LUA_MULTRET for a variable number of returns. int LuaPCall(int narg, int nresults); ! // ! bool SendLuaErrorEvent(int status, int top); // Get the wxEventType that Lua may currently be in, wxEVT_NULL if not in an *************** *** 793,796 **** --- 813,825 ---- // ----------------------------------------------------------------------- + // Try to compile the Lua program. Creates new lua_State to test for syntax + // errors and sends error events. See wxlua_errorinfo() for errMsg and line_num. + int CompileString(const wxString &script, const wxString& name = wxEmptyString, + wxString* errMsg = NULL, int* line_num = NULL); + int CompileBuffer(const unsigned char buf[], size_t size, const wxString &name = wxEmptyString, + wxString* errMsg = NULL, int* line_num = NULL); + + // ----------------------------------------------------------------------- + // Break a currently running Lua program by setting the Lua debug hook to // be called for anything and breaking as soon as possible by calling |