core/vm/sp_vm_function.h
author David Anderson <dvander@alliedmods.net>
Thu Jan 25 22:39:12 2007 +0000 (2007-01-25)
changeset 371 71b0caa3aaa8
parent 348 b30ce8321295
child 502 4530ea065a8b
permissions -rw-r--r--
renamed relevant areas to SorucePawn
     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, int flags);
    39 	virtual int PushFloat(float number);
    40 	virtual int PushFloatByRef(float *number, int flags);
    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 public:
    50 	void Set(uint32_t code_addr, IPluginContext *plugin);
    51 private:
    52 	int _PushString(const char *string, int sz_flags, int cp_flags, size_t len);
    53 	inline int SetError(int err)
    54 	{
    55 		m_errorstate = err;
    56 		return err;
    57 	}
    58 private:
    59 	uint32_t m_codeaddr;
    60 	IPluginContext *m_pContext;
    61 	cell_t m_params[SP_MAX_EXEC_PARAMS];
    62 	ParamInfo m_info[SP_MAX_EXEC_PARAMS];
    63 	unsigned int m_curparam;
    64 	int m_errorstate;
    65 	CFunction *m_pNext;
    66 };
    67 
    68 #endif //_INCLUDE_SOURCEMOD_BASEFUNCTION_H_