NET:LavishScriptAPI.Delegates.EventTarget

From Lavish Software Wiki
Jump to navigation Jump to search

Overview

LavishScriptAPI.Delegates.EventTarget describes the delegate used to implement LavishScript event targets (receivers...) through .NET.

Reference Library

Lavish.InnerSpace.dll

Fully Qualified Name

LavishScriptAPI.Delegates.EventTarget

Declaration

public delegate void EventTarget([In] int argc, [In] uint argvToken, [In] Object ThisObject);

Parameters

  • [In] int argc
The count of arguments passed to this function. There will always be at least 1, the name of the command (modelled after C console program design).
  • [In] uint argvToken
The array of strings passed to this function (char *argv[]). Because the C++ to managed call cannot marshal this properly, the parameter is passed as a token in the form of a uint, and individual parameters can be retrieved with InnerSpace.GetArg.
  • [In] Object ThisObject
Reserved. Do not use.

Return Value

None

Examples

C#

   public class HelloWorld
   {
       /* Instantiate our class, so we can use the instance destructor to do required cleanup when we unload */
       public static HelloWorld Instance = new HelloWorld();
       ~HelloWorld()
       {
           /* Detach from the event so we dont cause crashes */
           LavishScript.Events.DetachEventTarget(LavishScript.Events.RegisterEvent("Event_HelloWorld"), Eventdel_HelloWorld);
       }
       public static void Main()
       {
           /* Attach to the event */
           LavishScript.Events.AttachEventTarget(LavishScript.Events.RegisterEvent("Event_HelloWorld"), Eventdel_HelloWorld);

           /* For the purpose of this example, let's fire the event ourselves */
           string[] argv = new string[4];
           argv[0] = "Zero";
           argv[1] = "One";
           argv[2] = "Two";
           argv[3] = "Three";
           LavishScript.Events.ExecuteEvent(EventID, 4, argv);
       }
       /* Keep an instance of the delegate, so we dont end up trying to detach using a new delegate implicitly... */
       internal static LavishScriptAPI.Delegates.EventTarget Eventdel_HelloWorld = Event_HelloWorld;
       /* Our event target function */
       public static void Event_HelloWorld( int argc,  uint argv, Object ThisObject)
       {
           /* The event has been fired. argc is now the count of arguments, and argv is the token for GetArg */

           /* Let's echo the event name and the parameter count */
           InnerSpace.Echo("Event_HelloWorld " + argc.ToString());
           /* Now let's echo each parameter individually */
           for (uint i = 0; i < argc; i++)
           {
               /* Echo the arg number, then the value */
               InnerSpace.Echo(i.ToString() + " = " + InnerSpace.GetArg<string>(i,argv));
           }
           /* all done! */
           InnerSpace.Echo("------------------");
       }
   }


See Also