dvander@2193: /**
dvander@2193: * vim: set ts=4 :
dvander@2193: * =============================================================================
dvander@2193: * SourcePawn
dvander@2193: * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
dvander@2193: * =============================================================================
dvander@2193: *
dvander@2193: * This program is free software; you can redistribute it and/or modify it under
dvander@2193: * the terms of the GNU General Public License, version 3.0, as published by the
dvander@2193: * Free Software Foundation.
dvander@2193: *
dvander@2193: * This program is distributed in the hope that it will be useful, but WITHOUT
dvander@2193: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
dvander@2193: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
dvander@2193: * details.
dvander@2193: *
dvander@2193: * You should have received a copy of the GNU General Public License along with
dvander@2193: * this program. If not, see .
dvander@2193: *
dvander@2193: * As a special exception, AlliedModders LLC gives you permission to link the
dvander@2193: * code of this program (as well as its derivative works) to "Half-Life 2," the
dvander@2193: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
dvander@2193: * by the Valve Corporation. You must obey the GNU General Public License in
dvander@2193: * all respects for all other code used. Additionally, AlliedModders LLC grants
dvander@2193: * this exception to all derivative works. AlliedModders LLC defines further
dvander@2193: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
dvander@2193: * or .
dvander@2193: *
dvander@2193: * Version: $Id$
dvander@2193: */
dvander@2193:
dvander@2193: #ifndef _INCLUDE_SOURCEMOD_BASEFUNCTION_H_
dvander@2193: #define _INCLUDE_SOURCEMOD_BASEFUNCTION_H_
dvander@2193:
dvander@2193: #include
dvander@2193:
dvander@2193: class BaseRuntime;
dvander@2193:
dvander@2193: using namespace SourcePawn;
dvander@2193:
dvander@2193: struct ParamInfo
dvander@2193: {
dvander@2193: int flags; /* Copy-back flags */
dvander@2193: bool marked; /* Whether this is marked as being used */
dvander@2193: cell_t local_addr; /* Local address to free */
dvander@2193: cell_t *phys_addr; /* Physical address of our copy */
dvander@2193: cell_t *orig_addr; /* Original address to copy back to */
dvander@2193: ucell_t size; /* Size of array in bytes */
dvander@2193: struct
dvander@2193: {
dvander@2193: bool is_sz; /* is a string */
dvander@2193: int sz_flags; /* has sz flags */
dvander@2193: } str;
dvander@2193: };
dvander@2193:
dvander@2193: class CPlugin;
dvander@2226: class JitFunction;
dvander@2193:
dvander@2193: class CFunction : public IPluginFunction
dvander@2193: {
dvander@2193: friend class SourcePawnEngine;
dvander@2193: public:
dvander@2226: CFunction(BaseRuntime *pRuntime,
dvander@2193: funcid_t fnid,
dvander@2193: uint32_t pub_id);
dvander@2193: public:
dvander@2193: virtual int PushCell(cell_t cell);
dvander@2193: virtual int PushCellByRef(cell_t *cell, int flags);
dvander@2193: virtual int PushFloat(float number);
dvander@2193: virtual int PushFloatByRef(float *number, int flags);
dvander@2193: virtual int PushArray(cell_t *inarray, unsigned int cells, int copyback);
dvander@2193: virtual int PushString(const char *string);
dvander@2193: virtual int PushStringEx(char *buffer, size_t length, int sz_flags, int cp_flags);
dvander@2193: virtual int Execute(cell_t *result);
dvander@2193: virtual void Cancel();
dvander@2193: virtual int CallFunction(const cell_t *params, unsigned int num_params, cell_t *result);
dvander@2193: virtual IPluginContext *GetParentContext();
dvander@2193: bool IsRunnable();
dvander@2193: funcid_t GetFunctionID();
dvander@2193: int Execute2(IPluginContext *ctx, cell_t *result);
dvander@2193: int CallFunction2(IPluginContext *ctx,
dvander@2193: const cell_t *params,
dvander@2193: unsigned int num_params,
dvander@2193: cell_t *result);
dvander@2193: public:
dvander@2226: void Set(BaseRuntime *runtime, funcid_t fnid, uint32_t pub_id);
dvander@2193: private:
dvander@2193: int _PushString(const char *string, int sz_flags, int cp_flags, size_t len);
dvander@2193: int SetError(int err);
dvander@2193: private:
dvander@2193: BaseRuntime *m_pRuntime;
dvander@2193: cell_t m_params[SP_MAX_EXEC_PARAMS];
dvander@2193: ParamInfo m_info[SP_MAX_EXEC_PARAMS];
dvander@2193: unsigned int m_curparam;
dvander@2193: int m_errorstate;
dvander@2193: funcid_t m_FnId;
dvander@2193: };
dvander@2193:
dvander@2193: #endif //_INCLUDE_SOURCEMOD_BASEFUNCTION_H_