parse a string

BlitzMax Forums/BlitzMax Beginners Area/parse a string

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

SuperStrict

Type Ttest
	Field a:Int=1
	Field b:Int=2
	Field c:Float=3.5

	Field newevent:TEvent=New TEvent
	
	Function eventhook:Object(id:Int,data:Object,context:Object)
		If Ttest(context) Ttest(context).ev TEvent(data);Return data	
	EndFunction
	
	Method New()
		AddHook EmitEventHook,eventhook,Self
	End Method
	
	Method Free()
		RemoveHook EmitEventHook,eventhook
		GCCollect()
	End Method
	
	Method ev(event:TEvent)
		If event.id=$999666
			newevent.id=$999555
			newevent.extra=Self
			EmitEvent newevent
		EndIf
	End Method
	
End Type

Function test2:Object(id:Int,data:Object,context:Object)
	Local ev:TEvent=TEvent(data)
	
	If ev.id=$999555
		Local p:Ttest=Ttest(ev.extra)
	
		DebugLog p.a
		DebugLog p.b
		DebugLog p.c
	EndIf
	
	Return data
EndFunction

AddHook EmitEventHook,test2

Local t:Ttest=New Ttest

Local a:TEvent=New TEvent

a.id=$999666
EmitEvent a
End


Some older code from me, from a topic elsewhere. Study it, it shows you how to send a type to a function through an event.