Difference between revisions of "NET:LavishScriptAPI.Delegates.CommandTarget"

From Lavish Software Wiki
Jump to navigation Jump to search
 
 
(2 intermediate revisions by the same user not shown)
Line 12: Line 12:
  
 
== Declaration ==
 
== Declaration ==
  public delegate int CommandTarget([In] int argc, [In] uint argvToken);
+
  public delegate int CommandTarget([In] string[] args);
  
 
=== Parameters ===
 
=== Parameters ===
* [In] int argc
+
* [In] string[] args
: The count of arguments passed to this functionThere will always be at least 1, the name of the command (modelled after C console program design).
+
: The individual parameters passed to this command.  The first parameter (args[0]) is always 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 [[NET:InnerSpaceAPI.InnerSpace.GetArg|InnerSpace.GetArg]].  The first parameter is always the name of the command (modelled after C console program design).
 
  
 
=== Return Value ===
 
=== Return Value ===
Line 26: Line 24:
 
== Examples ==
 
== Examples ==
 
=== C# ===
 
=== C# ===
; Simple command that will echo each individual argument in the form #=value. This example does not show adding the command to LavishScript or later removing the command.
+
; Simple command that will echo each individual argument in the form #=value. This example does not show adding the command to LavishScript or later removing the command.
using InnerSpaceAPI;
+
  using InnerSpaceAPI;
using LavishScriptAPI;
+
  using LavishScriptAPI;
using LavishVMAPI;
+
  using LavishVMAPI;
 
+
        LavishScriptAPI.Delegates.CommandTarget CMDdel_MyCommand = CMD_MyCommand;
+
        static public int MyCommand(string[] args)
        static public int CommandTarget(int argc, uint argvToken)
+
        {
        {
+
    using (new FrameLock(true))
            Frame.Lock(); /* ensure that the command gets executed in one frame. if executed from the main thread, it will anyway. */
+
    {
            for (uint arg = 0; arg < argc; arg++)
+
                InnerSpace.Echo("MyCommand ("+args.Length.ToString()+" args)");
            {
+
                for (int i = 0; i < args.Length; i++)
                InnerSpace.Echo(arg.ToString() + "=" + InnerSpace.GetArg<string>(arg, argv));
+
                {
            }
+
                    InnerSpace.Echo(i.ToString() + ": " + args[i]);
            Frame.Unlock();
+
                }
        }
+
            }
 +
        }
  
 
== See Also ==
 
== See Also ==

Latest revision as of 16:37, 7 March 2008

Overview

LavishScriptAPI.Delegates.CommandTarget describes the delegate used to implement LavishScript commands through .NET.

Reference Library

Lavish.InnerSpace.dll

Fully Qualified Name

LavishScriptAPI.Delegates.CommandTarget

Declaration

public delegate int CommandTarget([In] string[] args);

Parameters

  • [In] string[] args
The individual parameters passed to this command. The first parameter (args[0]) is always the name of the command (modelled after C console program design).

Return Value

  • int
The command's return value. A negative value indicates a "fatal" error, which would end a LavishScript script. Any further return value specialization is command-specific.

Examples

C#

; Simple command that will echo each individual argument in the form #=value. This example does not show adding the command to LavishScript or later removing the command.
 using InnerSpaceAPI;
 using LavishScriptAPI;
 using LavishVMAPI;

        static public int MyCommand(string[] args)
        {
	    using (new FrameLock(true))
	    {
               InnerSpace.Echo("MyCommand ("+args.Length.ToString()+" args)");
               for (int i = 0; i < args.Length; i++)
               {
                   InnerSpace.Echo(i.ToString() + ": " + args[i]);
               }
            }
        }

See Also