added ability to use NULL_STRING in KeyValues natives
authorDavid Anderson <dvander@alliedmods.net>
Fri Jun 22 14:59:26 2007 +0000 (2007-06-22)
changeset 1000aefbd36eaf91
parent 999 8d7e956f996d
child 1001 8de56a71f200
added ability to use NULL_STRING in KeyValues natives
core/smn_keyvalues.cpp
core/vm/sp_vm_basecontext.cpp
core/vm/sp_vm_basecontext.h
plugins/include/core.inc
plugins/include/keyvalues.inc
public/sourcepawn/sp_vm_api.h
     1.1 --- a/core/smn_keyvalues.cpp	Fri Jun 22 04:35:27 2007 +0000
     1.2 +++ b/core/smn_keyvalues.cpp	Fri Jun 22 14:59:26 2007 +0000
     1.3 @@ -92,7 +92,7 @@
     1.4  	}
     1.5  
     1.6  	char *key, *value;
     1.7 -	pCtx->LocalToString(params[2], &key);
     1.8 +	pCtx->LocalToStringNULL(params[2], &key);
     1.9  	pCtx->LocalToString(params[3], &value);
    1.10  
    1.11  	pStk->pCurRoot.front()->SetString(key, value);
    1.12 @@ -117,7 +117,7 @@
    1.13  	}
    1.14  
    1.15  	char *key;
    1.16 -	pCtx->LocalToString(params[2], &key);
    1.17 +	pCtx->LocalToStringNULL(params[2], &key);
    1.18  
    1.19  	pStk->pCurRoot.front()->SetInt(key, params[3]);
    1.20  
    1.21 @@ -143,7 +143,7 @@
    1.22  	char *key;
    1.23  	cell_t *addr;
    1.24  	uint64 value;
    1.25 -	pCtx->LocalToString(params[2], &key);
    1.26 +	pCtx->LocalToStringNULL(params[2], &key);
    1.27  	pCtx->LocalToPhysAddr(params[3], &addr);
    1.28  
    1.29  	value = static_cast<uint64>(*addr);
    1.30 @@ -169,7 +169,7 @@
    1.31  	}
    1.32  
    1.33  	char *key;
    1.34 -	pCtx->LocalToString(params[2], &key);
    1.35 +	pCtx->LocalToStringNULL(params[2], &key);
    1.36  
    1.37  	pStk->pCurRoot.front()->SetFloat(key, sp_ctof(params[3]));
    1.38  
    1.39 @@ -193,7 +193,7 @@
    1.40  	}
    1.41  
    1.42  	char *key;
    1.43 -	pCtx->LocalToString(params[2], &key);
    1.44 +	pCtx->LocalToStringNULL(params[2], &key);
    1.45  
    1.46  	Color color(params[3], params[4], params[5], params[6]);
    1.47  	pStk->pCurRoot.front()->SetColor(key, color);
    1.48 @@ -219,7 +219,7 @@
    1.49  
    1.50  	const char *value;
    1.51  	char *key, *defvalue;
    1.52 -	pCtx->LocalToString(params[2], &key);
    1.53 +	pCtx->LocalToStringNULL(params[2], &key);
    1.54  	pCtx->LocalToString(params[5], &defvalue);
    1.55  
    1.56  	value = pStk->pCurRoot.front()->GetString(key, defvalue);
    1.57 @@ -246,7 +246,7 @@
    1.58  
    1.59  	int value;
    1.60  	char *key;
    1.61 -	pCtx->LocalToString(params[2], &key);
    1.62 +	pCtx->LocalToStringNULL(params[2], &key);
    1.63  
    1.64  	value = pStk->pCurRoot.front()->GetInt(key, params[3]);
    1.65  
    1.66 @@ -271,7 +271,7 @@
    1.67  
    1.68  	float value;
    1.69  	char *key;
    1.70 -	pCtx->LocalToString(params[2], &key);
    1.71 +	pCtx->LocalToStringNULL(params[2], &key);
    1.72  
    1.73  	value = pStk->pCurRoot.front()->GetFloat(key, sp_ctof(params[3]));
    1.74  
    1.75 @@ -297,7 +297,7 @@
    1.76  	Color color;
    1.77  	char *key;
    1.78  	cell_t *r, *g, *b, *a;
    1.79 -	pCtx->LocalToString(params[2], &key);
    1.80 +	pCtx->LocalToStringNULL(params[2], &key);
    1.81  	pCtx->LocalToPhysAddr(params[3], &r);
    1.82  	pCtx->LocalToPhysAddr(params[4], &g);
    1.83  	pCtx->LocalToPhysAddr(params[5], &b);
    1.84 @@ -331,7 +331,7 @@
    1.85  	char *key;
    1.86  	cell_t *addr, *defvalue;
    1.87  	uint64 value;
    1.88 -	pCtx->LocalToString(params[2], &key);
    1.89 +	pCtx->LocalToStringNULL(params[2], &key);
    1.90  	pCtx->LocalToPhysAddr(params[3], &addr);
    1.91  	pCtx->LocalToPhysAddr(params[4], &defvalue);
    1.92  
     2.1 --- a/core/vm/sp_vm_basecontext.cpp	Fri Jun 22 04:35:27 2007 +0000
     2.2 +++ b/core/vm/sp_vm_basecontext.cpp	Fri Jun 22 14:59:26 2007 +0000
     2.3 @@ -83,6 +83,15 @@
     2.4  	} else {
     2.5  		m_pNullVec = NULL;
     2.6  	}
     2.7 +
     2.8 +	if (FindPubvarByName("NULL_STRING", &index) == SP_ERROR_NONE)
     2.9 +	{
    2.10 +		sp_pubvar_t *pubvar;
    2.11 +		GetPubvarByIndex(index, &pubvar);
    2.12 +		m_pNullString = pubvar->offs;
    2.13 +	} else {
    2.14 +		m_pNullString = NULL;
    2.15 +	}
    2.16  }
    2.17  
    2.18  void BaseContext::FlushFunctionCache()
    2.19 @@ -992,6 +1001,22 @@
    2.20  	return pFunc;
    2.21  }
    2.22  
    2.23 +int BaseContext::LocalToStringNULL(cell_t local_addr, char **addr)
    2.24 +{
    2.25 +	int err;
    2.26 +	if ((err = LocalToString(local_addr, addr)) != SP_ERROR_NONE)
    2.27 +	{
    2.28 +		return err;
    2.29 +	}
    2.30 +
    2.31 +	if ((cell_t *)*addr == m_pNullString)
    2.32 +	{
    2.33 +		*addr = NULL;
    2.34 +	}
    2.35 +
    2.36 +	return SP_ERROR_NONE;
    2.37 +}
    2.38 +
    2.39  #if defined SOURCEMOD_BUILD
    2.40  SourceMod::IdentityToken_t *BaseContext::GetIdentity()
    2.41  {
     3.1 --- a/core/vm/sp_vm_basecontext.h	Fri Jun 22 04:35:27 2007 +0000
     3.2 +++ b/core/vm/sp_vm_basecontext.h	Fri Jun 22 14:59:26 2007 +0000
     3.3 @@ -70,6 +70,7 @@
     3.4  		SourceMod::IdentityToken_t *GetIdentity();
     3.5  		void SetIdentity(SourceMod::IdentityToken_t *token);
     3.6  		cell_t *GetNullRef(SP_NULL_TYPE type);
     3.7 +		int LocalToStringNULL(cell_t local_addr, char **addr);
     3.8  #endif
     3.9  	public: //IPluginDebugInfo
    3.10  		int LookupFile(ucell_t addr, const char **filename);
    3.11 @@ -86,6 +87,7 @@
    3.12  #if defined SOURCEMOD_BUILD
    3.13  		SourceMod::IdentityToken_t *m_pToken;
    3.14  		cell_t *m_pNullVec;
    3.15 +		cell_t *m_pNullString;
    3.16  #endif
    3.17  		char m_MsgCache[1024];
    3.18  		bool m_CustomMsg;
     4.1 --- a/plugins/include/core.inc	Fri Jun 22 04:35:27 2007 +0000
     4.2 +++ b/plugins/include/core.inc	Fri Jun 22 14:59:26 2007 +0000
     4.3 @@ -91,7 +91,8 @@
     4.4  	bool:required,			/**< Whether or not to require */
     4.5  };
     4.6  
     4.7 -public Float:NULL_VECTOR[3];	/**< Pass this into certain functions to act as a C++ NULL */
     4.8 +public Float:NULL_VECTOR[3];		/**< Pass this into certain functions to act as a C++ NULL */
     4.9 +public const String:NULL_STRING[1];	/**< pass this into certain functions to act as a C++ NULL */
    4.10  
    4.11  #define AUTOLOAD_EXTENSIONS
    4.12  #define REQUIRE_EXTENSIONS
     5.1 --- a/plugins/include/keyvalues.inc	Fri Jun 22 04:35:27 2007 +0000
     5.2 +++ b/plugins/include/keyvalues.inc	Fri Jun 22 14:59:26 2007 +0000
     5.3 @@ -49,7 +49,7 @@
     5.4   * Sets a string value of a KeyValues key.
     5.5   *
     5.6   * @param kv			KeyValues Handle.
     5.7 - * @param key			Name of the key.
     5.8 + * @param key			Name of the key, or NULL_STRING.
     5.9   * @param value			String value.
    5.10   * @noreturn
    5.11   * @error				Invalid Handle.
    5.12 @@ -60,7 +60,7 @@
    5.13   * Sets an integer value of a KeyValues key.
    5.14   *
    5.15   * @param kv			KeyValues Handle.
    5.16 - * @param key			Name of the key.
    5.17 + * @param key			Name of the key, or NULL_STRING.
    5.18   * @param value			Value number.
    5.19   * @noreturn
    5.20   * @error				Invalid Handle.
    5.21 @@ -71,7 +71,7 @@
    5.22   * Sets a large integer value of a KeyValues key.
    5.23   *
    5.24   * @param kv			KeyValues Handle.
    5.25 - * @param key			Name of the key.
    5.26 + * @param key			Name of the key, or NULL_STRING.
    5.27   * @param value			Large integer value (0=High bits, 1=Low bits)
    5.28   * @noreturn
    5.29   * @error				Invalid Handle.
    5.30 @@ -82,7 +82,7 @@
    5.31   * Sets a floating point value of a KeyValues key.
    5.32   *
    5.33   * @param kv			KeyValues Handle.
    5.34 - * @param key			Name of the key.
    5.35 + * @param key			Name of the key, or NULL_STRING.
    5.36   * @param value			Floating point value.
    5.37   * @noreturn
    5.38   * @error				Invalid Handle.
    5.39 @@ -93,7 +93,7 @@
    5.40   * Sets a set of color values of a KeyValues key.
    5.41   *
    5.42   * @param kv			KeyValues Handle.
    5.43 - * @param key			Name of the key.
    5.44 + * @param key			Name of the key, or NULL_STRING.
    5.45   * @param r				Red value.
    5.46   * @param g				Green value.
    5.47   * @param b				Blue value.
    5.48 @@ -107,7 +107,7 @@
    5.49   * Retrieves a string value from a KeyValues key.
    5.50   *
    5.51   * @param kv			KeyValues Handle.
    5.52 - * @param key			Name of the key.
    5.53 + * @param key			Name of the key, or NULL_STRING.
    5.54   * @param value			Buffer to store key value in.
    5.55   * @param maxlength		Maximum length of the value buffer.
    5.56   * @param defvalue		Optional default value to use if the key is not found.
    5.57 @@ -120,7 +120,7 @@
    5.58   * Retrieves an integer value from a KeyValues key.
    5.59   *
    5.60   * @param kv			KeyValues Handle.
    5.61 - * @param key			Name of the key.
    5.62 + * @param key			Name of the key, or NULL_STRING.
    5.63   * @param defvalue		Optional default value to use if the key is not found.
    5.64   * @return				Integer value of the key.
    5.65   * @error				Invalid Handle.
    5.66 @@ -131,7 +131,7 @@
    5.67   * Retrieves a floating point value from a KeyValues key.
    5.68   *
    5.69   * @param kv			KeyValues Handle.
    5.70 - * @param key			Name of the key.
    5.71 + * @param key			Name of the key, or NULL_STRING.
    5.72   * @param defvalue		Optional default value to use if the key is not found.
    5.73   * @return				Floating point value of the key.
    5.74   * @error				Invalid Handle.
    5.75 @@ -142,7 +142,7 @@
    5.76   * Retrieves a set of color values from a KeyValues key.
    5.77   *
    5.78   * @param kv			KeyValues Handle.
    5.79 - * @param key			Name of the key.
    5.80 + * @param key			Name of the key, or NULL_STRING.
    5.81   * @param r				Red value, set by reference.
    5.82   * @param g				Green value, set by reference. 
    5.83   * @param b				Blue value, set by reference. 
    5.84 @@ -156,7 +156,7 @@
    5.85   * Retrieves a large integer value from a KeyValues key.
    5.86   *
    5.87   * @param kv			KeyValues Handle.
    5.88 - * @param key			Name of the key.
    5.89 + * @param key			Name of the key, or NULL_STRING.
    5.90   * @param value			Array to represent the large integer.
    5.91   * @param defvalue		Optional default value to use if the key is not found.
    5.92   * @noreturn
     6.1 --- a/public/sourcepawn/sp_vm_api.h	Fri Jun 22 04:35:27 2007 +0000
     6.2 +++ b/public/sourcepawn/sp_vm_api.h	Fri Jun 22 14:59:26 2007 +0000
     6.3 @@ -56,6 +56,7 @@
     6.4  	enum SP_NULL_TYPE
     6.5  	{
     6.6  		SP_NULL_VECTOR = 0,		/**< Float[3] reference */
     6.7 +		SP_NULL_STRING = 1,		/**< const String[1] reference */
     6.8  	};
     6.9  #endif
    6.10  
    6.11 @@ -555,6 +556,15 @@
    6.12  		 * @return			cell_t address to compare to.
    6.13  		 */
    6.14  		virtual cell_t *GetNullRef(SP_NULL_TYPE type) =0;
    6.15 +
    6.16 +		/**
    6.17 +		 * @brief Converts a local address to a physical string, and allows
    6.18 +		 * for NULL_STRING to be set.
    6.19 +		 *
    6.20 +		 * @param local_addr	Local address in plugin.
    6.21 +		 * @param addr			Destination output pointer.
    6.22 +		 */
    6.23 +		virtual int LocalToStringNULL(cell_t local_addr, char **addr) =0;
    6.24  #endif
    6.25  	};
    6.26