core/vm/sp_vm_basecontext.h
author Scott Ehlert <ds@alliedmods.net>
Sun Jul 15 08:00:26 2007 +0000 (2007-07-15)
changeset 1116 40cc5e9f0f1b
parent 1000 aefbd36eaf91
child 1231 17badaf66ce4
permissions -rw-r--r--
Removed strange debugging code
dvander@371
     1
/**
ds@653
     2
 * vim: set ts=4 :
dvander@371
     3
 * ================================================================
dvander@371
     4
 * SourcePawn (C)2004-2007 AlliedModders LLC.  All rights reserved.
dvander@371
     5
 * ================================================================
dvander@371
     6
 *
dvander@371
     7
 * This file is not open source and may not be copied without explicit
dvander@371
     8
 * written permission of AlliedModders LLC.  This file may not be redistributed 
dvander@371
     9
 * in whole or significant part.
dvander@371
    10
 * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
dvander@371
    11
 *
dvander@371
    12
 * Version: $Id$
dvander@371
    13
 */
dvander@371
    14
dvander@159
    15
#ifndef _INCLUDE_SOURCEPAWN_BASECONTEXT_H_
dvander@159
    16
#define _INCLUDE_SOURCEPAWN_BASECONTEXT_H_
dvander@159
    17
dvander@159
    18
#include "sp_vm_api.h"
dvander@327
    19
#include "sp_vm_function.h"
dvander@327
    20
dvander@327
    21
/**
dvander@327
    22
 * :TODO: Make functions allocate as a lump instead of individual allocations!
dvander@327
    23
 */
dvander@159
    24
dvander@159
    25
namespace SourcePawn
dvander@159
    26
{
dvander@159
    27
	class BaseContext : 
dvander@159
    28
		public IPluginContext,
dvander@159
    29
		public IPluginDebugInfo
dvander@159
    30
	{
dvander@159
    31
	public:
dvander@159
    32
		BaseContext(sp_context_t *ctx);
dvander@327
    33
		~BaseContext();
dvander@159
    34
	public: //IPluginContext
dvander@159
    35
		IVirtualMachine *GetVirtualMachine();
dvander@159
    36
		sp_context_t *GetContext();
dvander@159
    37
		bool IsDebugging();
dvander@159
    38
		int SetDebugBreak(SPVM_DEBUGBREAK newpfn, SPVM_DEBUGBREAK *oldpfn);
dvander@159
    39
		IPluginDebugInfo *GetDebugInfo();
faluco@641
    40
		int HeapAlloc(unsigned int cells, cell_t *local_addr, cell_t **phys_addr);
faluco@641
    41
		int HeapPop(cell_t local_addr);
faluco@641
    42
		int HeapRelease(cell_t local_addr);
faluco@641
    43
		int FindNativeByName(const char *name, uint32_t *index);
faluco@641
    44
		int GetNativeByIndex(uint32_t index, sp_native_t **native);
faluco@641
    45
		uint32_t GetNativesNum();
faluco@641
    46
		int FindPublicByName(const char *name, uint32_t *index);
faluco@641
    47
		int GetPublicByIndex(uint32_t index, sp_public_t **publicptr);
faluco@641
    48
		uint32_t GetPublicsNum();
faluco@641
    49
		int GetPubvarByIndex(uint32_t index, sp_pubvar_t **pubvar);
faluco@641
    50
		int FindPubvarByName(const char *name, uint32_t *index);
faluco@641
    51
		int GetPubvarAddrs(uint32_t index, cell_t *local_addr, cell_t **phys_addr);
faluco@641
    52
		uint32_t GetPubVarsNum();
faluco@641
    53
		int LocalToPhysAddr(cell_t local_addr, cell_t **phys_addr);
faluco@641
    54
		int LocalToString(cell_t local_addr, char **addr);
faluco@641
    55
		int StringToLocal(cell_t local_addr, size_t chars, const char *source);
faluco@641
    56
		int StringToLocalUTF8(cell_t local_addr, size_t maxbytes, const char *source, size_t *wrtnbytes);
faluco@641
    57
		int PushCell(cell_t value);
faluco@641
    58
		int PushCellArray(cell_t *local_addr, cell_t **phys_addr, cell_t array[], unsigned int numcells);
faluco@641
    59
		int PushString(cell_t *local_addr, char **phys_addr, const char *string);
faluco@641
    60
		int PushCellsFromArray(cell_t array[], unsigned int numcells);
faluco@641
    61
		int BindNatives(const sp_nativeinfo_t *natives, unsigned int num, int overwrite);
faluco@641
    62
		int BindNative(const sp_nativeinfo_t *native);
faluco@641
    63
		int BindNativeToAny(SPVM_NATIVE_FUNC native);
faluco@641
    64
		int Execute(uint32_t code_addr, cell_t *result);
faluco@641
    65
		cell_t ThrowNativeErrorEx(int error, const char *msg, ...);
faluco@641
    66
		cell_t ThrowNativeError(const char *msg, ...);
faluco@641
    67
		IPluginFunction *GetFunctionByName(const char *public_name);
faluco@641
    68
		IPluginFunction *GetFunctionById(funcid_t func_id);
dvander@262
    69
#if defined SOURCEMOD_BUILD
faluco@641
    70
		SourceMod::IdentityToken_t *GetIdentity();
dvander@262
    71
		void SetIdentity(SourceMod::IdentityToken_t *token);
dvander@938
    72
		cell_t *GetNullRef(SP_NULL_TYPE type);
dvander@1000
    73
		int LocalToStringNULL(cell_t local_addr, char **addr);
dvander@262
    74
#endif
dvander@159
    75
	public: //IPluginDebugInfo
faluco@641
    76
		int LookupFile(ucell_t addr, const char **filename);
faluco@641
    77
		int LookupFunction(ucell_t addr, const char **name);
faluco@641
    78
		int LookupLine(ucell_t addr, uint32_t *line);
faluco@290
    79
	public:
faluco@290
    80
		void SetContext(sp_context_t *_ctx);
dvander@159
    81
	private:
dvander@240
    82
		void SetErrorMessage(const char *msg, va_list ap);
dvander@692
    83
		void FlushFunctionCache();
dvander@692
    84
		void RefreshFunctionCache();
dvander@240
    85
	private:
dvander@159
    86
		sp_context_t *ctx;
dvander@262
    87
#if defined SOURCEMOD_BUILD
dvander@262
    88
		SourceMod::IdentityToken_t *m_pToken;
dvander@938
    89
		cell_t *m_pNullVec;
dvander@1000
    90
		cell_t *m_pNullString;
dvander@262
    91
#endif
dvander@240
    92
		char m_MsgCache[1024];
dvander@240
    93
		bool m_CustomMsg;
dvander@240
    94
		bool m_InExec;
dvander@327
    95
		unsigned int m_funcsnum;
dvander@692
    96
#if 0
dvander@327
    97
		CFunction **m_priv_funcs;
dvander@692
    98
#endif
dvander@327
    99
		CFunction **m_pub_funcs;
dvander@159
   100
	};
dvander@159
   101
};
dvander@159
   102
dvander@159
   103
#endif //_INCLUDE_SOURCEPAWN_BASECONTEXT_H_