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

From Lavish Software Wiki
Jump to navigation Jump to search
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 31: Line 29:
 
  using LavishVMAPI;
 
  using LavishVMAPI;
  
        LavishScriptAPI.Delegates.CommandTarget CMDdel_MyCommand = CMD_MyCommand;
+
         static public int MyCommand(string[] args)
         static public int MyCommand(int argc, uint argv)
 
 
         {
 
         {
            Frame.Lock(); /* ensure that the command gets executed in one frame. if executed from the main thread, it will anyway. */
+
    using (new FrameLock(true))
            for (uint arg = 0; arg < argc; arg++)
+
    {
            {
+
              InnerSpace.Echo("MyCommand ("+args.Length.ToString()+" args)");
                InnerSpace.Echo(arg.ToString() + "=" + InnerSpace.GetArg<string>(arg, argv));
+
              for (int i = 0; i < args.Length; i++)
 +
              {
 +
                  InnerSpace.Echo(i.ToString() + ": " + args[i]);
 +
              }
 
             }
 
             }
            Frame.Unlock();
 
 
         }
 
         }
  

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