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