(No Title)
Alright, so the MUD project had some success tonight. Allow me to elaborate architecturally:
In anticipation of Python, Coming Soon™, I envision a method in which commands may be inserted into the normal command search list at arbitrary positions based upon some XML-based, Coming Soon™, command map. Let’s take a look at an example of what I see for the future before I go into tonight’s progress:
C++ (Built-In) Command Map for G
go
giggle
gasp
In the fashion of Circle, the command parser would traverse this list (assuming the command started with “G”), matching the typed command to the first appropriate function call (“g”=”go”, “gi”=”giggle”, etc.).
Now, imagine an XML tag for an inserted Python function:
“name” defines the official name of the function, “src” tells the server where to grab the Python code, and “priority” tells the server where to insert the function. The task of “priority” is accomplished by the server acting as though a user typed the “priority” string. The appropriate handler mapping (in this case: “ga”=”gasp”) is performed. At this point, the new Python command is inserted BEFORE the mapped command, in essence giving the inserted command priority over the shortened string “ga”. Of course, a bottom priority for the command could be specified by giving “h” as the priority value.
Now, on to today’s work:
The big question is, how do we make Python and C++ coexist? The answer lies in function pointers. Both the C++ calls and the Python embedded function lookups return pointers to functions (albeit of far different structures). So, I created a class Command, which is an abstract class. The class is made to be abstract by including the pure virtual function CallFunction(). Currently, there is a CxxHandler class that inherits Command and provides an implementation of CallFunction(). This CallFunction() interacts with a function pointer (to a C++ function) that points to a C++ function defined by macro as a friend of the Server class. The anticipated PyHandler class will fill a similar role, but it will include a private function pointer to the Python interpreter’s location of the Python function. CallFunction() will resolve the syntactic details of the different function calls.
This way, a normal linked list that holds Command objects can be used without exceptions based upon the implementing language. Function calls are wrapped on a per-instance basis by CallFunction().
This architecture was proven tonight, as a handler called “fallback” was defined to print “Huh?” when an unknown command is typed. This is currently the default and only command available to the growing interpreter.
Yay!