2
* Copyright (c) 2002 by Michael J. Roberts. All Rights Reserved.
4
* Please see the accompanying license file, LICENSE.TXT, for information
5
* on using and copying this software.
9
vmcore.h - T3 VM "core" interpreter - example function set definition
11
This is an example of how to define custom intrinsic (i.e., native C++)
12
functions for the T3 VM. An intrinsic function is a function written in
13
C++, and part of the application executable, that can be called from TADS
14
code (i.e., from within .t source).
16
This file can be used as a template for creating custom intrinsics.
17
Simply make a copy of this entire file, and then make the following
20
1. Change the #ifndef symbol from VMCORE_H to a different name of your
21
own choosing - usually, the name matches the name of the .h file itself.
22
This symbol appears three times in the file, so you should be careful to
23
change all three to the same new symbol.
25
2. Change the name of class CVmBifSample to a name of your own choosing.
26
Choose a name that describes the custom function set you're defining. This
27
name appears in the class definition and also in each entry in the list
28
near the bottom of the file, so make sure to change every occurrence of the
29
name to the same new name.
31
3. Change the names of the functions themselves. Note that each function
32
name appears twice - first in the class definition near the start of the
33
file, then again in the initialization list at the bottom of the file. You
34
can add and delete functions as you wish. If you add new functions, simply
35
copy an existing definition and change its name, being sure to add the
36
function in both the class definition and the list at the bottom of the
39
4. You must, of course, provide an implementation for each of your
40
functions. Do that in a new .cpp file corresponding to your new header
41
file. Make sure you #include your new header file from your new .cpp file.
42
You can use the implementations in vmcore.cpp as a template for your new
45
5. Make a copy of the file vmbifreg_core.cpp. Add a #include line for
46
the new copy of this file you have created (you can add it right after the
47
#include for vmbiftad.h). Also add a MAKE_ENTRY() line for your new
48
function set - you can add it where the comments indicate in your copy of
49
vmbifreg_core.cpp. The MAKE_ENTRY() line would look like this:
51
MAKE_ENTRY("core-sample/010000", G_bif_core_sample);
53
Use the same name you use for the variable defined in the initialization
54
list near the end of the file. For the string, you can use anything you
55
want, but you should choose something reasonably long and descriptive to
56
avoid overlapping with anyone else's function set identifiers.
58
6. Take vmbifreg_core.obj out of the application build, and replace it
59
with the copy you created in step 5.
61
7. Take vmcore.obj out of the application build, and replace it with your
62
new .cpp file from step 4.
64
8. Change the variable name G_bif_sample near the end of this file to a
65
different name of your own choosing.
67
9. Create a TADS header file, for inclusion in your TADS (.t) source
68
code, defining your intrinsic functions. See the sample file "core.h"
70
intrinsic 'core-sample/010000'
72
// display the given string
75
// read a line of text from the keyboard, and return it as a string
79
You MUST define the intrinsic functions in the EXACT SAME ORDER that they
80
appear in the initialization list near the end of this file. For the name
81
of the function set (the 'core-sample/010000' string), you must use the
82
EXACT SAME string you used in the MAKE_ENTRY() definition in step 5.
84
Everything else in this file is boilerplate text, so you shouldn't have
85
to change anything else.
90
04/06/02 MJRoberts - Creation
98
/* ------------------------------------------------------------------------ */
100
* Our sample built-in functions. Each function we define here will be
101
* callable as an intrinsic function from TADS source code.
103
* This is only the interface definition. The actual implementations of
104
* these functions appear in our .cpp file.
106
* Note that every function has the same C++ interface. This has nothing
107
* to do with the arguments that the TADS program passes to these
108
* functions; the functions get their TADS arguments from the VM stack.
109
* See the implementations for details.
111
class CVmBifSample: public CVmBif
114
static void display_text(VMG_ uint argc);
115
static void read_text(VMG_ uint argc);
118
#endif /* VMCORE_H */
120
/* ------------------------------------------------------------------------ */
122
* Sample function set vector. Define this only if VMBIF_DEFINE_VECTOR has
125
* IMPORTANT - this definition is outside the #ifdef VMCORE_H section of
126
* the header file, because we specifically want this part of the file to
127
* be able to be included multiple times.
129
* ALSO IMPORTANT - the ORDER of the definitions here is significant. You
130
* must use the EXACT SAME ORDER in your "intrinsic" definition in the
131
* header file you create for inclusion in your TADS (.t) source code.
133
#ifdef VMBIF_DEFINE_VECTOR
135
void (*G_bif_sample[])(VMG_ uint) =
137
&CVmBifSample::display_text,
138
&CVmBifSample::read_text