core/vm/sp_vm_function.h
author David Anderson <dvander@alliedmods.net>
Wed Aug 15 20:18:15 2007 +0000 (2007-08-15)
changeset 1339 02e8f2c0f8af
parent 1330 ab94316bb52b
child 1908 318e0a01aef9
permissions -rw-r--r--
SourceMod will now spit out errors for scripts that become corrupt and would otherwise be crashing Core. if you get these errors contact the dev team.
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourcePawn
     5  * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
     6  * =============================================================================
     7  *
     8  * This program is free software; you can redistribute it and/or modify it under
     9  * the terms of the GNU General Public License, version 3.0, as published by the
    10  * Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful, but WITHOUT
    13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    15  * details.
    16  *
    17  * You should have received a copy of the GNU General Public License along with
    18  * this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to link the
    21  * code of this program (as well as its derivative works) to "Half-Life 2," the
    22  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    23  * by the Valve Corporation.  You must obey the GNU General Public License in
    24  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    25  * this exception to all derivative works.  AlliedModders LLC defines further
    26  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    27  * or <http://www.sourcemod.net/license.php>.
    28  *
    29  * Version: $Id$
    30  */
    31 
    32 #ifndef _INCLUDE_SOURCEMOD_BASEFUNCTION_H_
    33 #define _INCLUDE_SOURCEMOD_BASEFUNCTION_H_
    34 
    35 #include "sm_globals.h"
    36 
    37 struct ParamInfo
    38 {
    39 	int flags;			/* Copy-back flags */
    40 	bool marked;		/* Whether this is marked as being used */
    41 	cell_t local_addr;	/* Local address to free */
    42 	cell_t *phys_addr;	/* Physical address of our copy */
    43 	cell_t *orig_addr;	/* Original address to copy back to */
    44 	ucell_t size;		/* Size of array in bytes */
    45 	struct
    46 	{
    47 		bool is_sz;		/* is a string */
    48 		int sz_flags;	/* has sz flags */
    49 	} str;
    50 };
    51 
    52 class CPlugin;
    53 
    54 class CFunction : public IPluginFunction
    55 {
    56 	friend class SourcePawnEngine;
    57 public:
    58 	CFunction(uint32_t code_addr, IPluginContext *pContext, funcid_t fnid);
    59 public:
    60 	virtual int PushCell(cell_t cell);
    61 	virtual int PushCellByRef(cell_t *cell, int flags);
    62 	virtual int PushFloat(float number);
    63 	virtual int PushFloatByRef(float *number, int flags);
    64 	virtual int PushArray(cell_t *inarray, unsigned int cells, int copyback);
    65 	virtual int PushString(const char *string);
    66 	virtual int PushStringEx(char *buffer, size_t length, int sz_flags, int cp_flags);
    67 	virtual int Execute(cell_t *result);
    68 	virtual void Cancel();
    69 	virtual int CallFunction(const cell_t *params, unsigned int num_params, cell_t *result);
    70 	virtual IPluginContext *GetParentContext();
    71 	inline bool IsInvalidated()
    72 	{
    73 		return m_Invalid;
    74 	}
    75 	inline void Invalidate()
    76 	{
    77 		m_Invalid = true;
    78 	}
    79 	bool IsRunnable();
    80 	funcid_t GetFunctionID();
    81 public:
    82 	void Set(uint32_t code_addr, IPluginContext *plugin, funcid_t fnid);
    83 private:
    84 	int _PushString(const char *string, int sz_flags, int cp_flags, size_t len);
    85 	inline int SetError(int err)
    86 	{
    87 		m_errorstate = err;
    88 		return err;
    89 	}
    90 private:
    91 	uint32_t m_codeaddr;
    92 	IPluginContext *m_pContext;
    93 	sp_context_t *m_pCtx;
    94 	cell_t m_params[SP_MAX_EXEC_PARAMS];
    95 	ParamInfo m_info[SP_MAX_EXEC_PARAMS];
    96 	unsigned int m_curparam;
    97 	int m_errorstate;
    98 	CFunction *m_pNext;
    99 	bool m_Invalid;
   100 	funcid_t m_FnId;
   101 };
   102 
   103 #endif //_INCLUDE_SOURCEMOD_BASEFUNCTION_H_