sourcepawn/include/sp_vm_api.h
changeset 237 b2210331d415
parent 184 ecd216d00146
child 239 cd48418120ba
     1.1 --- a/sourcepawn/include/sp_vm_api.h	Sun Dec 31 03:02:40 2006 +0000
     1.2 +++ b/sourcepawn/include/sp_vm_api.h	Sun Dec 31 22:33:47 2006 +0000
     1.3 @@ -314,6 +314,67 @@
     1.4  		virtual int Execute(uint32_t funcid, cell_t *result) =0;
     1.5  	};
     1.6  
     1.7 +	struct ErrorTraceInfo
     1.8 +	{
     1.9 +		const char *filename;
    1.10 +		unsigned int line;
    1.11 +		const char *function;
    1.12 +	};
    1.13 +
    1.14 +	class IContextErrorInfo
    1.15 +	{
    1.16 +		/**
    1.17 +		 * @brief Returns the integer error code.
    1.18 +		 *
    1.19 +		 * @return			Integer error code.
    1.20 +		 */
    1.21 +		virtual int GetErrorCode() =0;
    1.22 +
    1.23 +		/**
    1.24 +		 * @brief Returns a string describing the error.
    1.25 +		 *
    1.26 +		 * @return			Error string.
    1.27 +		 */
    1.28 +		virtual const char *GetErrorString() =0;
    1.29 +
    1.30 +		/**
    1.31 +		 * @brief Returns whether debug info is available.
    1.32 +		 *
    1.33 +		 * @return			True if debug info is available, false otherwise.
    1.34 +		 */
    1.35 +		virtual bool DebugInfoAvailable() =0;
    1.36 +
    1.37 +		/**
    1.38 +		 * @brief Returns a custom error message.
    1.39 +		 *
    1.40 +		 * @return			A pointer to a custom error message, or NULL otherwise.
    1.41 +		 */
    1.42 +		virtual const char *GetCustomErrorString() =0;
    1.43 +
    1.44 +		/**
    1.45 +		 * @brief Returns the number of calls in the call backtrace.
    1.46 +		 * NOTE: Tracers are ordered from 0 to N-1, where 0 is the top of the trace.
    1.47 +		 *
    1.48 +		 * @return			Number of calls in the trace.
    1.49 +		 */
    1.50 +		virtual unsigned int TraceCallCount() =0;
    1.51 +
    1.52 +		/**
    1.53 +		 * @brief Returns trace info for a specific point in the backtrace.
    1.54 +		 *
    1.55 +		 * @param call		The call trace index (from 0 to N-1).
    1.56 +		 * @param trace		An ErrorTraceInfo buffer to store information.
    1.57 +		 * @return			True if successful, false otherwise.
    1.58 +		 */
    1.59 +		virtual bool GetTraceInfo(unsigned int call, ErrorTraceInfo *trace) =0;
    1.60 +	};
    1.61 +
    1.62 +	class IDebugListener
    1.63 +	{
    1.64 +	public:
    1.65 +		virtual void OnContextExecuteError(IPluginContext *ctx, IContextErrorInfo *error) =0;
    1.66 +	};
    1.67 +
    1.68  	/**
    1.69  	 * @brief Contains helper functions used by VMs and the host app
    1.70  	 */
    1.71 @@ -321,17 +382,17 @@
    1.72  	{
    1.73  	public:
    1.74  		/**
    1.75 -		* Loads a named file from a file pointer.  
    1.76 -		* Using this means base memory will be allocated by the VM.
    1.77 -		* 
    1.78 -		* @param fp			File pointer.  May be at any offset.  Not closed on return.
    1.79 -		* @param err		Optional error code pointer.
    1.80 -		* @return			A new plugin structure.
    1.81 -		*/	
    1.82 +		 * @brief Loads a named file from a file pointer.  
    1.83 +		 * Note: Using this means the memory will be allocated by the VM.
    1.84 +		 * 
    1.85 +		 * @param fp			File pointer.  May be at any offset.  Not closed on return.
    1.86 +		 * @param err		Optional error code pointer.
    1.87 +		 * @return			A new plugin structure.
    1.88 +		 */	
    1.89  		virtual sp_plugin_t *LoadFromFilePointer(FILE *fp, int *err) =0;
    1.90  	
    1.91  		/**
    1.92 -		 * Loads a file from a base memory address.
    1.93 +		 * @brief Loads a file from a base memory address.
    1.94  		 *	
    1.95  		 * @param base		Base address of the plugin's memory region.
    1.96  		 * @param plugin	If NULL, a new plugin pointer is returned.
    1.97 @@ -349,7 +410,7 @@
    1.98  		virtual int FreeFromMemory(sp_plugin_t *plugin) =0;
    1.99  
   1.100  		/**
   1.101 -		 * Creates a new IContext from a context handle.
   1.102 +		 * @brief Creates a new IContext from a context handle.
   1.103  		 *
   1.104  		 * @param ctx		Context to use as a basis for the IPluginContext.
   1.105  		 * @return			New IPluginContext handle.
   1.106 @@ -357,14 +418,14 @@
   1.107  		virtual IPluginContext *CreateBaseContext(sp_context_t *ctx) =0;
   1.108  
   1.109  		/** 
   1.110 -		 * Frees a base context.  Does not free the sp_context_t it holds.
   1.111 +		 * @brief Frees a base context.  Does not free the sp_context_t it holds.
   1.112  		 *
   1.113  		 * @param ctx		Context pointer to free.
   1.114  		 */
   1.115  		virtual void FreeBaseContext(IPluginContext *ctx) =0;
   1.116  
   1.117  		/**
   1.118 -		 * Allocates large blocks of temporary memory.
   1.119 +		 * @brief Allocates large blocks of temporary memory.
   1.120  		 * 
   1.121  		 * @param size		Size of memory to allocate.
   1.122  		 * @return			Pointer to memory, NULL if allocation failed.
   1.123 @@ -372,14 +433,14 @@
   1.124  		virtual void *BaseAlloc(size_t size) =0;
   1.125  
   1.126  		/**
   1.127 -		 * Frees memory allocated with BaseAlloc.
   1.128 +		 * @brief Frees memory allocated with BaseAlloc.
   1.129  		 *
   1.130  		 * @param memory	Memory address to free.
   1.131  		 */
   1.132  		virtual void BaseFree(void *memory) =0;
   1.133  
   1.134  		/**
   1.135 -		 * Allocates executable memory.
   1.136 +		 * @brief Allocates executable memory.
   1.137  		 *
   1.138  		 * @param size		Size of memory to allocate.
   1.139  		 * @return			Pointer to memory, NULL if allocation failed.
   1.140 @@ -387,13 +448,50 @@
   1.141  		virtual void *ExecAlloc(size_t size) =0;
   1.142  
   1.143  		/**
   1.144 -		 * Frees executable memory.
   1.145 +		 * @brief Frees executable memory.
   1.146  		 *
   1.147  		 * @param address	Address to free.
   1.148  		 */
   1.149  		virtual void ExecFree(void *address) =0;
   1.150 +
   1.151 +		/**
   1.152 +		 * @brief Sets the debug listener. 
   1.153 +		 *
   1.154 +		 * @param listener	Pointer to an IDebugListener.
   1.155 +		 * @return			Old IDebugListener, or NULL if none.
   1.156 +		 */
   1.157 +		virtual IDebugListener *SetDebugListener(IDebugListener *pListener) =0;
   1.158 +		
   1.159 +		/**
   1.160 +		 * @brief Returns the number of plugins on the call stack.
   1.161 +		 *
   1.162 +		 * @return			Number of contexts in the call stack.
   1.163 +		 */
   1.164 +		virtual unsigned int GetContextCallCount() =0;
   1.165 +
   1.166 +		/**
   1.167 +		 * @brief Throws an error and halts any current execution.
   1.168 +		 *
   1.169 +		 * @param error		The error number to set.
   1.170 +		 * @param msg		Custom error message format.  NULL to use default.
   1.171 +		 * @param ...		Message format arguments, if any.
   1.172 +		 */
   1.173 +		virtual void ThrowNativeErrorEx(int error, const char *msg, ...) =0;
   1.174 +
   1.175 +		/**
   1.176 +		 * @brief Throws a native error and halts any current execution.
   1.177 +		 * NOTE: This is a wrapper around ThrowError() for convenience.
   1.178 +		 *
   1.179 +		 * @param msg		Custom error message format.  NULL to set no message.
   1.180 +		 * @param ...		Message format arguments, if any.
   1.181 +		 * @return			0 for convenience.
   1.182 +		 */
   1.183 +		virtual void ThrowNativeError(const char *msg, ...) =0;
   1.184  	};
   1.185  
   1.186 +	/**
   1.187 +	 * @brief Dummy class for encapsulating private compilation data.
   1.188 +	 */
   1.189  	class ICompilation
   1.190  	{
   1.191  	public: