Added the ability for extensions to invoke arbitrary natives (bug 3605, r=ds,theY4Kman).
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
/**
|
||||
* vim: set ts=4 :
|
||||
* =============================================================================
|
||||
* SourceMod
|
||||
* Copyright (C) 2004-2009 AlliedModders LLC. All rights reserved.
|
||||
* =============================================================================
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 3.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* As a special exception, AlliedModders LLC gives you permission to link the
|
||||
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
||||
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
||||
* by the Valve Corporation. You must obey the GNU General Public License in
|
||||
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
||||
* this exception to all derivative works. AlliedModders LLC defines further
|
||||
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
||||
* or <http://www.sourcemod.net/license.php>.
|
||||
*
|
||||
* Version: $Id$
|
||||
*/
|
||||
|
||||
#ifndef _INCLUDE_SOURCEMOD_INATIVEINVOKER_H_
|
||||
#define _INCLUDE_SOURCEMOD_INATIVEINVOKER_H_
|
||||
|
||||
/**
|
||||
* @file INativeInvoker.h
|
||||
* @brief Interface for invoking natives.
|
||||
*/
|
||||
|
||||
#include <IShareSys.h>
|
||||
|
||||
#define SMINTERFACE_NINVOKE_NAME "INativeInterface"
|
||||
#define SMINTERFACE_NINVOKE_VERSION 1
|
||||
|
||||
#define NINVOKE_DEFAULT_MEMORY 16384
|
||||
|
||||
namespace SourceMod
|
||||
{
|
||||
class INativeInvoker : public SourcePawn::ICallable
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Virtual destructor - use delete to free this.
|
||||
*/
|
||||
virtual ~INativeInvoker()
|
||||
{
|
||||
}
|
||||
public:
|
||||
/**
|
||||
* @brief Begins a native call.
|
||||
*
|
||||
* During a call's preparation, no new calls may be started.
|
||||
*
|
||||
* @param pContext Context to invoke native under.
|
||||
* @param name Name of native.
|
||||
* @return True if native was found, false otherwise.
|
||||
*/
|
||||
virtual bool Start(IPluginContext *pContext, const char *name) = 0;
|
||||
|
||||
/**
|
||||
* @brief Invokes the native. The preparation state is cleared immediately, meaning that
|
||||
* this object can be re-used after or even from inside the native being called.
|
||||
*
|
||||
* @param result Optional pointer to retrieve a result.
|
||||
* @return SP_ERROR return code.
|
||||
*/
|
||||
virtual int Invoke(cell_t *result) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Factory for dealing with native invocations.
|
||||
*/
|
||||
class INativeInterface : public SMInterface
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Creates a virtual plugin. This can be used as an environment to invoke natives.
|
||||
*
|
||||
* IPluginRuntime objects must be freed with the delete operator.
|
||||
*
|
||||
* @param name Name, or NULL for anonymous.
|
||||
* @param bytes Number of bytes for memory (NINVOKE_DEFAULT_MEMORY recommended).
|
||||
* @return New runtime, or NULL on failure.
|
||||
*/
|
||||
virtual IPluginRuntime *CreateRuntime(const char *name, size_t bytes) = 0;
|
||||
|
||||
/**
|
||||
* @brief Creates an object that can be used to invoke a single native code.
|
||||
*
|
||||
* @return New native invoker (free with delete).
|
||||
*/
|
||||
virtual INativeInvoker *CreateInvoker() = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* _INCLUDE_SOURCEMOD_INATIVEINVOKER_H_ */
|
||||
@@ -76,5 +76,6 @@
|
||||
//#define SMEXT_ENABLE_TEXTPARSERS
|
||||
//#define SMEXT_ENABLE_USERMSGS
|
||||
//#define SMEXT_ENABLE_TRANSLATOR
|
||||
//#define SMEXT_ENABLE_NINVOKE
|
||||
|
||||
#endif // _INCLUDE_SOURCEMOD_EXTENSION_CONFIG_H_
|
||||
|
||||
@@ -97,6 +97,9 @@ IUserMessages *usermsgs = NULL;
|
||||
#if defined SMEXT_ENABLE_TRANSLATOR
|
||||
ITranslator *translator = NULL;
|
||||
#endif
|
||||
#if defined SMEXT_ENABLE_NINVOKE
|
||||
INativeInterface *ninvoke = NULL;
|
||||
#endif
|
||||
|
||||
/** Exports the main interface */
|
||||
PLATFORM_EXTERN_C IExtensionInterface *GetSMExtAPI()
|
||||
|
||||
@@ -91,6 +91,9 @@
|
||||
#if defined SMEXT_ENABLE_TRANSLATOR
|
||||
#include <ITranslator.h>
|
||||
#endif
|
||||
#if defined SMEXT_ENABLE_NINVOKE
|
||||
#include <INativeInvoker.h>
|
||||
#endif
|
||||
|
||||
#if defined SMEXT_CONF_METAMOD
|
||||
#include <ISmmPlugin.h>
|
||||
@@ -289,6 +292,9 @@ extern IUserMessages *usermsgs;
|
||||
#if defined SMEXT_ENABLE_TRANSLATOR
|
||||
extern ITranslator *translator;
|
||||
#endif
|
||||
#if defined SMEXT_ENABLE_NINVOKE
|
||||
extern INativeInterface *ninvoke;
|
||||
#endif
|
||||
|
||||
#if defined SMEXT_CONF_METAMOD
|
||||
PLUGIN_GLOBALVARS();
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
|
||||
/** SourcePawn Engine API Version */
|
||||
#define SOURCEPAWN_ENGINE_API_VERSION 4
|
||||
#define SOURCEPAWN_ENGINE2_API_VERSION 2
|
||||
#define SOURCEPAWN_ENGINE2_API_VERSION 3
|
||||
|
||||
#if !defined SOURCEMOD_BUILD
|
||||
#define SOURCEMOD_BUILD
|
||||
@@ -876,6 +876,11 @@ namespace SourcePawn
|
||||
* @return True on success, false on failure.
|
||||
*/
|
||||
virtual bool GetKey(int k, void **value) =0;
|
||||
|
||||
/**
|
||||
* @brief Clears the last native error.
|
||||
*/
|
||||
virtual void ClearLastNativeError() =0;
|
||||
};
|
||||
|
||||
|
||||
@@ -1252,6 +1257,15 @@ namespace SourcePawn
|
||||
* Initialize() succeeded.
|
||||
*/
|
||||
virtual void Shutdown() =0;
|
||||
|
||||
/**
|
||||
* @brief Creates an empty plugin with a blob of memory.
|
||||
*
|
||||
* @param name Name, for debugging (NULL for anonymous).
|
||||
* @param bytes Number of bytes of memory (hea+stk).
|
||||
* @return New runtime, or NULL if not enough memory.
|
||||
*/
|
||||
virtual IPluginRuntime *CreateEmptyRuntime(const char *name, uint32_t memory) =0;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user