core/vm/sp_vm_basecontext.h
author David Anderson <dvander@alliedmods.net>
Sun Oct 14 17:55:02 2007 +0000 (2007-10-14)
changeset 1545 4ceff5fa5fdd
parent 1382 5399d6f24417
child 1638 2980312c1c94
permissions -rw-r--r--
fixed compat wrappers including core stuff
     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_SOURCEPAWN_BASECONTEXT_H_
    33 #define _INCLUDE_SOURCEPAWN_BASECONTEXT_H_
    34 
    35 #include "sp_vm_api.h"
    36 #include "sp_vm_function.h"
    37 
    38 /**
    39  * :TODO: Make functions allocate as a lump instead of individual allocations!
    40  */
    41 
    42 namespace SourcePawn
    43 {
    44 	class BaseContext : 
    45 		public IPluginContext,
    46 		public IPluginDebugInfo
    47 	{
    48 	public:
    49 		BaseContext(sp_context_t *ctx);
    50 		~BaseContext();
    51 	public: //IPluginContext
    52 		IVirtualMachine *GetVirtualMachine();
    53 		sp_context_t *GetContext();
    54 		bool IsDebugging();
    55 		int SetDebugBreak(SPVM_DEBUGBREAK newpfn, SPVM_DEBUGBREAK *oldpfn);
    56 		IPluginDebugInfo *GetDebugInfo();
    57 		int HeapAlloc(unsigned int cells, cell_t *local_addr, cell_t **phys_addr);
    58 		int HeapPop(cell_t local_addr);
    59 		int HeapRelease(cell_t local_addr);
    60 		int FindNativeByName(const char *name, uint32_t *index);
    61 		int GetNativeByIndex(uint32_t index, sp_native_t **native);
    62 		uint32_t GetNativesNum();
    63 		int FindPublicByName(const char *name, uint32_t *index);
    64 		int GetPublicByIndex(uint32_t index, sp_public_t **publicptr);
    65 		uint32_t GetPublicsNum();
    66 		int GetPubvarByIndex(uint32_t index, sp_pubvar_t **pubvar);
    67 		int FindPubvarByName(const char *name, uint32_t *index);
    68 		int GetPubvarAddrs(uint32_t index, cell_t *local_addr, cell_t **phys_addr);
    69 		uint32_t GetPubVarsNum();
    70 		int LocalToPhysAddr(cell_t local_addr, cell_t **phys_addr);
    71 		int LocalToString(cell_t local_addr, char **addr);
    72 		int StringToLocal(cell_t local_addr, size_t chars, const char *source);
    73 		int StringToLocalUTF8(cell_t local_addr, size_t maxbytes, const char *source, size_t *wrtnbytes);
    74 		int PushCell(cell_t value);
    75 		int PushCellArray(cell_t *local_addr, cell_t **phys_addr, cell_t array[], unsigned int numcells);
    76 		int PushString(cell_t *local_addr, char **phys_addr, const char *string);
    77 		int PushCellsFromArray(cell_t array[], unsigned int numcells);
    78 		int BindNatives(const sp_nativeinfo_t *natives, unsigned int num, int overwrite);
    79 		int BindNative(const sp_nativeinfo_t *native);
    80 		int BindNativeToAny(SPVM_NATIVE_FUNC native);
    81 		int Execute(uint32_t code_addr, cell_t *result);
    82 		cell_t ThrowNativeErrorEx(int error, const char *msg, ...);
    83 		cell_t ThrowNativeError(const char *msg, ...);
    84 		IPluginFunction *GetFunctionByName(const char *public_name);
    85 		IPluginFunction *GetFunctionById(funcid_t func_id);
    86 #if defined SOURCEMOD_BUILD
    87 		SourceMod::IdentityToken_t *GetIdentity();
    88 		void SetIdentity(SourceMod::IdentityToken_t *token);
    89 		cell_t *GetNullRef(SP_NULL_TYPE type);
    90 		int LocalToStringNULL(cell_t local_addr, char **addr);
    91 #endif
    92 		int BindNativeToIndex(uint32_t index, SPVM_NATIVE_FUNC native);
    93 	public: //IPluginDebugInfo
    94 		int LookupFile(ucell_t addr, const char **filename);
    95 		int LookupFunction(ucell_t addr, const char **name);
    96 		int LookupLine(ucell_t addr, uint32_t *line);
    97 	public:
    98 		void SetContext(sp_context_t *_ctx);
    99 	private:
   100 		void SetErrorMessage(const char *msg, va_list ap);
   101 		void FlushFunctionCache();
   102 		void RefreshFunctionCache();
   103 	private:
   104 		sp_context_t *ctx;
   105 #if defined SOURCEMOD_BUILD
   106 		SourceMod::IdentityToken_t *m_pToken;
   107 		cell_t *m_pNullVec;
   108 		cell_t *m_pNullString;
   109 #endif
   110 		char m_MsgCache[1024];
   111 		bool m_CustomMsg;
   112 		bool m_InExec;
   113 		unsigned int m_funcsnum;
   114 #if 0
   115 		CFunction **m_priv_funcs;
   116 #endif
   117 		CFunction **m_pub_funcs;
   118 	};
   119 };
   120 
   121 #endif //_INCLUDE_SOURCEPAWN_BASECONTEXT_H_