Add SMCParser.ParseString (#1817)
This commit is contained in:
		
							parent
							
								
									8538233985
								
							
						
					
					
						commit
						5d391fda07
					
				@ -29,6 +29,8 @@
 | 
				
			|||||||
 * Version: $Id$
 | 
					 * Version: $Id$
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "common_logic.h"
 | 
					#include "common_logic.h"
 | 
				
			||||||
#include <ITextParsers.h>
 | 
					#include <ITextParsers.h>
 | 
				
			||||||
#include <ISourceMod.h>
 | 
					#include <ISourceMod.h>
 | 
				
			||||||
@ -264,6 +266,32 @@ static cell_t SMC_ParseFile(IPluginContext *pContext, const cell_t *params)
 | 
				
			|||||||
	return (cell_t)p_err;
 | 
						return (cell_t)p_err;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static cell_t SMC_ParseString(IPluginContext *pContext, const cell_t *params)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						OpenHandle<ParseInfo> parse(pContext, params[1], g_TypeSMC);
 | 
				
			||||||
 | 
						if (!parse.Ok())
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						char *str;
 | 
				
			||||||
 | 
						pContext->LocalToString(params[2], &str);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						SMCStates states;
 | 
				
			||||||
 | 
						SMCError p_err = textparsers->ParseSMCStream(str,
 | 
				
			||||||
 | 
																	strlen(str),
 | 
				
			||||||
 | 
																	parse,
 | 
				
			||||||
 | 
																	&states,
 | 
				
			||||||
 | 
																	NULL,
 | 
				
			||||||
 | 
																	0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						cell_t *c_line, *c_col;
 | 
				
			||||||
 | 
						pContext->LocalToPhysAddr(params[3], &c_line);
 | 
				
			||||||
 | 
						pContext->LocalToPhysAddr(params[4], &c_col);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						*c_line = states.line;
 | 
				
			||||||
 | 
						*c_col = states.col;
 | 
				
			||||||
 | 
						return (cell_t)p_err;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static cell_t SMC_GetErrorString(IPluginContext *pContext, const cell_t *params)
 | 
					static cell_t SMC_GetErrorString(IPluginContext *pContext, const cell_t *params)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	const char *str = textparsers->GetSMCErrorString((SMCError)params[1]);
 | 
						const char *str = textparsers->GetSMCErrorString((SMCError)params[1]);
 | 
				
			||||||
@ -334,6 +362,7 @@ REGISTER_NATIVES(textNatives)
 | 
				
			|||||||
	// Transitional syntax support.
 | 
						// Transitional syntax support.
 | 
				
			||||||
	{"SMCParser.SMCParser",				SMC_CreateParser},
 | 
						{"SMCParser.SMCParser",				SMC_CreateParser},
 | 
				
			||||||
	{"SMCParser.ParseFile",				SMC_ParseFile},
 | 
						{"SMCParser.ParseFile",				SMC_ParseFile},
 | 
				
			||||||
 | 
						{"SMCParser.ParseString",			SMC_ParseString},
 | 
				
			||||||
	{"SMCParser.OnStart.set",			SMC_SetParseStart},
 | 
						{"SMCParser.OnStart.set",			SMC_SetParseStart},
 | 
				
			||||||
	{"SMCParser.OnEnd.set",				SMC_SetParseEnd},
 | 
						{"SMCParser.OnEnd.set",				SMC_SetParseEnd},
 | 
				
			||||||
	{"SMCParser.OnEnterSection.set",	SMCParser_OnEnterSection_set},
 | 
						{"SMCParser.OnEnterSection.set",	SMCParser_OnEnterSection_set},
 | 
				
			||||||
 | 
				
			|||||||
@ -147,6 +147,14 @@ methodmap SMCParser < Handle
 | 
				
			|||||||
	// @return              An SMCParseError result.
 | 
						// @return              An SMCParseError result.
 | 
				
			||||||
	public native SMCError ParseFile(const char[] file, int &line = 0, int &col = 0);
 | 
						public native SMCError ParseFile(const char[] file, int &line = 0, int &col = 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Parses raw UTF-8 text as an SMC file.
 | 
				
			||||||
 | 
						//
 | 
				
			||||||
 | 
						// @param string        A string containing an SMC file.
 | 
				
			||||||
 | 
						// @param line          An optional variable to store the last line number read.
 | 
				
			||||||
 | 
						// @param col           An optional variable to store the last column number read.
 | 
				
			||||||
 | 
						// @return              An SMCParseError result.
 | 
				
			||||||
 | 
						public native SMCError ParseString(const char[] string, int &line = 0, int &col = 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Sets the callback for receiving SMC_ParseStart events.
 | 
						// Sets the callback for receiving SMC_ParseStart events.
 | 
				
			||||||
	property SMC_ParseStart OnStart {
 | 
						property SMC_ParseStart OnStart {
 | 
				
			||||||
		public native set(SMC_ParseStart func);
 | 
							public native set(SMC_ParseStart func);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user