core/vm/sp_vm_function.h
author Borja Ferrer <faluco@alliedmods.net>
Thu May 10 22:51:56 2007 +0000 (2007-05-10)
changeset 762 e82fc0f89dc1
parent 653 ef60870067ff
child 1231 17badaf66ce4
permissions -rw-r--r--
added debug code for leak detection on plugins
     1 /**
     2  * vim: set ts=4 :
     3  * ================================================================
     4  * SourcePawn (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ================================================================
     6  *
     7  * This file is not open source and may not be copied without explicit
     8  * written permission of AlliedModders LLC.  This file may not be redistributed 
     9  * in whole or significant part.
    10  * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    11  *
    12  * Version: $Id$
    13  */
    14 
    15 #ifndef _INCLUDE_SOURCEMOD_BASEFUNCTION_H_
    16 #define _INCLUDE_SOURCEMOD_BASEFUNCTION_H_
    17 
    18 #include "sm_globals.h"
    19 
    20 struct ParamInfo
    21 {
    22 	int flags;			/* Copy-back flags */
    23 	bool marked;		/* Whether this is marked as being used */
    24 	cell_t local_addr;	/* Local address to free */
    25 	cell_t *phys_addr;	/* Physical address of our copy */
    26 	cell_t *orig_addr;	/* Original address to copy back to */
    27 	ucell_t size;		/* Size of array in bytes */
    28 	struct
    29 	{
    30 		bool is_sz;		/* is a string */
    31 		int sz_flags;	/* has sz flags */
    32 	} str;
    33 };
    34 
    35 class CPlugin;
    36 
    37 class CFunction : public IPluginFunction
    38 {
    39 	friend class SourcePawnEngine;
    40 public:
    41 	CFunction(uint32_t code_addr, IPluginContext *pContext);
    42 public:
    43 	virtual int PushCell(cell_t cell);
    44 	virtual int PushCellByRef(cell_t *cell, int flags);
    45 	virtual int PushFloat(float number);
    46 	virtual int PushFloatByRef(float *number, int flags);
    47 	virtual int PushArray(cell_t *inarray, unsigned int cells, int copyback);
    48 	virtual int PushString(const char *string);
    49 	virtual int PushStringEx(char *buffer, size_t length, int sz_flags, int cp_flags);
    50 	virtual int Execute(cell_t *result);
    51 	virtual void Cancel();
    52 	virtual int CallFunction(const cell_t *params, unsigned int num_params, cell_t *result);
    53 	virtual IPluginContext *GetParentContext();
    54 	inline bool IsInvalidated()
    55 	{
    56 		return m_Invalid;
    57 	}
    58 	inline void Invalidate()
    59 	{
    60 		m_Invalid = true;
    61 	}
    62 	bool IsRunnable();
    63 public:
    64 	void Set(uint32_t code_addr, IPluginContext *plugin);
    65 private:
    66 	int _PushString(const char *string, int sz_flags, int cp_flags, size_t len);
    67 	inline int SetError(int err)
    68 	{
    69 		m_errorstate = err;
    70 		return err;
    71 	}
    72 private:
    73 	uint32_t m_codeaddr;
    74 	IPluginContext *m_pContext;
    75 	sp_context_t *m_pCtx;
    76 	cell_t m_params[SP_MAX_EXEC_PARAMS];
    77 	ParamInfo m_info[SP_MAX_EXEC_PARAMS];
    78 	unsigned int m_curparam;
    79 	int m_errorstate;
    80 	CFunction *m_pNext;
    81 	bool m_Invalid;
    82 };
    83 
    84 #endif //_INCLUDE_SOURCEMOD_BASEFUNCTION_H_