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