Update regex and datapack includes to not use binding syntax.

This commit is contained in:
David Anderson 2015-08-12 11:52:57 -07:00
parent 17c4649651
commit bcfef75c5d
4 changed files with 124 additions and 30 deletions

View File

@ -377,5 +377,20 @@ REGISTER_NATIVES(datapacknatives)
{"GetPackPosition", smn_GetPackPosition},
{"SetPackPosition", smn_SetPackPosition},
{"IsPackReadable", smn_IsPackReadable},
// Methodmap versions.
{"DataPack.DataPack", smn_CreateDataPack},
{"DataPack.WriteCell", smn_WritePackCell},
{"DataPack.WriteFloat", smn_WritePackFloat},
{"DataPack.WriteString", smn_WritePackString},
{"DataPack.WriteFunction", smn_WritePackFunction},
{"DataPack.ReadCell", smn_ReadPackCell},
{"DataPack.ReadFloat", smn_ReadPackFloat},
{"DataPack.ReadString", smn_ReadPackString},
{"DataPack.ReadFunction", smn_ReadPackFunction},
{"DataPack.Reset", smn_ResetPack},
{"DataPack.Position.get", smn_GetPackPosition},
{"DataPack.Position.set", smn_SetPackPosition},
{"DataPack.IsReadable", smn_IsPackReadable},
{NULL, NULL}
};

View File

@ -194,5 +194,10 @@ const sp_nativeinfo_t regex_natives[] =
{"GetRegexSubString", GetRegexSubString},
{"MatchRegex", MatchRegex},
{"CompileRegex", CompileRegex},
// Methodmap versions/
{"Regex.GetSubString", GetRegexSubString},
{"Regex.Match", MatchRegex},
{"Regex.Regex", CompileRegex},
{NULL, NULL},
};

View File

@ -1,5 +1,5 @@
/**
* vim: set ts=4 :
* vim: set ts=4 sw=4 tw=99 noet :
* =============================================================================
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
* =============================================================================
@ -41,6 +41,70 @@
*/
enum DataPackPos: {};
// A DataPack allows serializing multiple variables into a single stream.
methodmap DataPack < Handle
{
// Creates a new data pack.
public native DataPack();
// Packs a normal cell into a data pack.
//
// @param cell Cell to add.
public native void WriteCell(any cell);
// Packs a float into a data pack.
//
// @param val Float to add.
public native void WriteFloat(float val);
// Packs a string into a data pack.
//
// @param str String to add.
public native void WriteString(const char[] str);
// Packs a function pointer into a data pack.
//
// @param fktptr Function pointer to add.
public native void WriteFunction(Function fktptr);
// Reads a cell from a data pack.
//
// @param pack Handle to the data pack.
public native any ReadCell();
// Reads a float from a data pack.
//
// @param pack Handle to the data pack.
public native float ReadFloat();
// Reads a string from a data pack.
//
// @param buffer Destination string buffer.
// @param maxlen Maximum length of output string buffer.
public native void ReadString(char[] buffer, maxlen);
// Reads a function pointer from a data pack.
//
// @return Function pointer.
public native Function ReadFunction();
// Resets the position in a data pack.
//
// @param clear If true, clears the contained data.
public native void Reset(bool clear=false);
// Returns whether or not a specified number of bytes from the data pack
// position to the end can be read.
//
// @param bytes Number of bytes to simulate reading.
public native bool IsReadable();
// The read or write position in a data pack.
property DataPackPos Position {
public native get();
public native set(DataPackPos pos);
}
};
/**
* Creates a new data pack.
@ -167,23 +231,3 @@ native void SetPackPosition(Handle pack, DataPackPos position);
*/
native bool IsPackReadable(Handle pack, int bytes);
methodmap DataPack < Handle
{
public DataPack() = CreateDataPack;
public WriteCell() = WritePackCell;
public WriteFloat() = WritePackFloat;
public WriteString() = WritePackString;
public WriteFunction() = WritePackFunction;
public ReadCell() = ReadPackCell;
public ReadFloat() = ReadPackFloat;
public ReadString() = ReadPackString;
public ReadFunction() = ReadPackFunction;
public Reset() = ResetPack;
public IsReadable() = IsPackReadable;
property DataPackPos Position {
public get() = GetPackPosition;
public set() = SetPackPosition;
}
};

View File

@ -1,5 +1,5 @@
/**
* vim: set ts=4 :
* vim: set ts=4 sw=4 tw=99 noet :
* =============================================================================
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
* =============================================================================
@ -92,6 +92,43 @@ enum RegexError
REGEX_ERROR_BADLENGTH = -32,
};
// Regular expression objects are used to match or decompose strings based on
// patterns.
methodmap Regex < Handle
{
// Compile a regular expression.
//
// @param pattern The regular expression pattern.
// @param flags General flags for the regular expression.
// @param error Error message encountered, if applicable.
// @param maxLen Maximum string length of the error buffer.
// @param errcode Regex type error code encountered, if applicable.
public native Regex(const char[] pattern, int flags = 0, char[] error="", int maxLen = 0, RegexError &errcode = REGEX_ERROR_NONE);
// Matches a string against a pre-compiled regular expression pattern.
//
// @param str The string to check.
// @param regex Regex Handle from CompileRegex()
// @param ret Error code, if applicable.
// @return Number of substrings found or -1 on failure.
//
// @note Use the regex handle passed to this function to extract
// matches with GetRegexSubString().
public native int Match(const char[] str, RegexError &ret = REGEX_ERROR_NONE);
// Returns a matched substring from a regex handle.
//
// Substring ids start at 0 and end at substrings-1, where substrings is the
// number returned by Regex.Match.
//
// @param regex The regex handle to extract data from.
// @param str_id The index of the expression to get - starts at 0, and ends at substrings - 1.
// @param buffer The buffer to set to the matching substring.
// @param maxlen The maximum string length of the buffer.
// @return True if a substring was found, False on fail/error
public native bool GetSubString(int str_id, char[] buffer, int maxlen);
};
/**
* Precompile a regular expression. Use this if you intend on using the
* same expression multiple times. Pass the regex handle returned here to
@ -132,13 +169,6 @@ native int MatchRegex(Handle regex, const char[] str, RegexError &ret = REGEX_ER
*/
native bool GetRegexSubString(Handle regex, int str_id, char[] buffer, int maxlen);
methodmap Regex < Handle
{
public Regex() = CompileRegex;
public Match() = MatchRegex;
public GetSubString() = GetRegexSubString;
};
/**
* Matches a string against a regular expression pattern.
*