Rice language front end.

RiceManager class

The front end of the Rice language is the RiceManager class. We describes the public members of the RiceManager class in this page.

In the following explanation, C# is assumed as the implementation language.

Constructor

First, you need get an instance of the RiceManager class.


public RiceManager(string filename)

public RiceManager(VirtualMachine vm)

public RiceManager(string filename)

It is a constructor that takes the path to the Rice source file as an argument. Parses the given source code to create and store a prototype of the user-defined class.

For example:

RiceManager manager = new RiceManager("c:\somewhere...\example.cook");


If the source file is correct as the Rice language, the constructor returns an instance of the RiceManager class. If there is a syntax error in the source file, the constructor will throw an exception.

See Exceptions for the exceptions that Rice throws.


An example of using the RiceManager (string filename) constructor.

1:

RiceManager rm = null;

2:

try {

3:

rm = new RiceManager("c:\somewhere...\example.cook");

4:

}

5:

catch(Exception e) {

6:

MessageBox.Show(e.Message); // Show exception message.

7:

}

public RiceManager(VirtualMachine vm)

It is a constructor that takes the VirtualMachine class as an argument. The VirtualMachine class already has prototypes of parsed user-defined classes. Use it to create an instance of the RiceManager class.

An instance of the VirtualMachine class is given as an argument in a member call of the Rtype derived class. You can't generate the VirtualMachine class directly, so you wouldn't use this constructor in normal script execution. This is a constructor used in special situations such as event handling and timer implementation.

Registration of built-in class

You can register Rtype-derived classes written in C # etc. as built-in classes.


public static void AddBuiltIn(string typename, PlainProtoTypeGetter pptg)

public static void RegisterClasses(string directoryPath)

public static void AddBuiltIn(string typename, PlainProtoTypeGetter pptg)

Registers a class name and a delegate.


ClassNameDescription
stringtypenameClass name in Rice.
PlainProtoTypeGetterpptgA delegete that returns Rtype-derived class.

Registration of a built-in class registers a delegate unlike Rice's user-defined class registration.

Definition of the delegate is:

public delegate Rtype PlainProtoTypeGetter();

When a built-in class is requested, the registered delegate is called and the instance is returned.

Note that the member function is static. Registered built-in classes are shared throughout Rice. All RiceManager instances will have the same set of built-in classes.


Suppose you have a built-in class "Rexample" and following members are defined in the class.

public const string TYPENAME = "example";

public static Rtype InstanceGetter() { return new Rexample(); }

Registration of the Rexample is:

RiceManager.AddBuiltIn(Rexample.TYPENAME, Rexample.InstanceGetter);


See Class implementation #1 for more information on Rtype-derived class implementations.

public static void RegisterClasses(string directoryPath)

Searches for dll files of all built-in classes under the directory specified by the argument.

This function does not register the built-in class. When it goes around the directory hierarchy and finds the corresponding dll file, it calls a specific function from it.

Call the AddBuiltIn function in the called function to register the built-in class. If there are the necessary preparations to use the built-in class, you can do that as well.


See Class implementation #2 for dynamic classloading instructions and directory patrol details.

Script execution

Once you have an instance of the RiceManager class, you can run the Rice script. Execution of the Rice script is started by calling the open method of Rice's user-defined class.


public void Run()

public Rtype Invoke(string methodSigneture, Queue<Rtype> argQueue)

public Rtype Invoke(string methodSigneture, Queue<Rtype> argQueue, bool argCheck)

public Rtype Invoke(Rclass rc, string methodname, Queue<Rtype> argqueue)

public Rtype Invoke(Rclass rc, string methodname, Queue<Rtype> argqueue, bool argCheck)

public void Run()

It calls the start() method of Rice's main class. An exception will be thrown if the main class or start () method is not defined.

The signature of the start() method is "open method void start()". That is, the start() method takes no arguments and has no return value. Therefore, the Run() function also has no arguments and no return value.


The following is an example of using the Run() function.

1:

// RiceManager is already generated.

2:

try {

3:

rm.Run();

4:

}

5:

catch(Exception e) {

6:

MessageBox.Show(e.Message); // Show exception message.

7:

}

public Rtype Invoke(string methodSigneture, Queue<Rtype> argQueue)
public Rtype Invoke(string methodSigneture, Queue<Rtype> argQueue, bool argCheck)

You can call any open method of Rice's main class if you use these member functions.

Assuming that Rice's main class has a method called "open method int sample(string str, int index)", to call this method from your application, do the following.

1:

Queue<Rtype> args = new Queue<Rtype>();

2:

args.Enqueue(new Rstring("example"));

3:

args.Enqueue(new Rint(0));

4:

Rint result = Invoke("sample(string,int)", args);

The first argument of the function specifies a signature of the open method to be called. The signature is a string that method name is followed by the class name of the argument enclosed in parentheses. If there are multiple arguments, those are separated with comma. With the sample method above, the signature would be "sample(string,int)". An exception will be thrown if there is no open method that matches the signature.

The second argument is arguments to pass to the method. It stores instances of the appropriate Rtype-derived class to the Queue<Rtype> in order of the signature arguments.

If there is no argument, the parentheses are empty. For example, if you call the start() method with the function, the first argument is "start()". In this case, the second argument must be an empty Queue<Rtype>. Please note that it is not null.

The result is an instance of the Rtype-derived class. If the return type of the method to be called is void, Rvoid class is returned.

First function does not consider whether the signature matches arguments or not. It is the programmer's responsibility to provide the correct arguments.

Second function can control checking whether the class and order of the second argument are the same as the signature. If third argument is true, execute the check. Otherwise, the check is not executed.

If the check is executed and the arguments do not match, an exception will be thrown.

public Rtype Invoke(Rclass rc, string methodSignature, Queue<Rtype> argqueue)
public Rtype Invoke(Rclass rc, string methodSignature, Queue<Rtype> argqueue, bool argCheck)

With these member functions, you can call any open method from a user-defined class other than the main class.

Since the user-defined class is treated as Rclass class inside Rice, pass an instance of appropriate Rclass class to the function as the first argument. The appropriate open method will be called from this instance.

The second and subsequent arguments are the same as the Invoke () function above.


You can't generate the Rclass class directly, so you wouldn't use these functions in normal script execution. These are functions used in special situations such as event handling and timer implementation.

Confirmation of method existence

You can check if the open method exists in the main class before running the Rice script.


public bool IsOpenMethodOfMain(string signature)

public bool IsOpenMethodOfMain(string signature)

Pass the signature of the open method you want to confirm. The signature is a string of a method name followed by the class name of the argument in parentheses. If there are multiple arguments, separate them with commas. In the case of the sample method above, the signature will be "sample(string,int)".

Returns true if the signature exists as an open method of the main class. Otherwise, returns false.

Message management

The RiceManager class has member functions for message management.


public static string GetMessage(string key)

public static string AddMessage(string key, string value)

public static string SetMessage(string key, string value)

public static void SetFromFile(string fileName)

public static void SetFromResource(ResourceManager manager)

public static void SetFromResource(ResourceManager manager, CultureInfo info)

public static bool ContainsKey(string key)


See Internationalization for more information.

Presetting a constant

In Rice, an identifier that returns a new instance with a constant value for each reference is called a constant.


public static bool RegisterConst(string name, PlainProtoTypeGetter pptg)

public static bool RegisterConst(string name, PlainProtoTypeGetter pptg)

Registers an identifier and a delegate. Except for the method name, it is the same as the registration of the built-in class.

When the constant is referenced, the registered delegate is called and the instance is returned.

Note that the member function is static. The preset constants are shared throughout Rice. All RiceManager instances will have the same set of constants.


Suppose you have a built-in class "Rexample" and following member is defined in the class.

internal static Rexample GetConst() {

return new Rexample("Set some value.");

}


To preset the constant "EXAM" that returns the Rexample:

RiceManager.RegisterConst("EXAM", Rexample.GetConst);


See Constants and Preset Constants for more information on constants.

Copyright © Rice All rights reserved.