Skip to content

Latest commit

 

History

History
241 lines (188 loc) · 6.12 KB

toby_app.h

File metadata and controls

241 lines (188 loc) · 6.12 KB
 
Feb 8, 2007
Feb 8, 2007
1
2
3
4
5
6
7
8
/*
* Toby -- A programming language for learning.
* Copyright (C) 2007 Ryan C. Gordon.
*
* Please refer to LICENSE.txt in the root directory of the source
* distribution for licensing details.
*/
9
10
11
#ifndef _INCL_TOBY_APP_H_
#define _INCL_TOBY_APP_H_
Jan 23, 2007
Jan 23, 2007
12
13
14
15
16
17
18
19
#ifdef __cplusplus
extern "C" {
#endif
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
Mar 18, 2008
Mar 18, 2008
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#if (defined(_MSC_VER) && (!defined inline))
#define inline __inline
#endif
/* needed for alloca(). */
#if defined(_MSC_VER) || defined(__MINGW32__)
#include <malloc.h>
#endif
#ifndef M_PI
#define M_PI (3.14159265358979323846)
#endif
/*
* Try to handle platforms where lua_Number isn't a double. Whenever
Jan 23, 2007
Jan 23, 2007
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
* specifying a numeric constant, try to use whole numbers, and wrap them
* in N(), so that we don't have the compiler do an unnecessary implicit cast:
*
* if (myLuaNum < N(0)) {}
*/
#ifdef N
#error N is defined somewhere.
#endif
#if defined(LUA_NUMBER_DOUBLE)
#define N(x) x##.0
#elif defined(LUA_NUMBER_FLOAT)
#define N(x) x##.0f
#else
#define N(x) x
#endif
#define STATICARRAYLEN(x) ( (sizeof ((x))) / (sizeof ((x)[0])) )
Feb 6, 2007
Feb 6, 2007
53
54
typedef struct TurtlePoint
Jan 23, 2007
Jan 23, 2007
55
56
57
{
lua_Number x;
lua_Number y;
Feb 6, 2007
Feb 6, 2007
58
59
60
61
62
63
64
65
66
67
68
69
70
71
} TurtlePoint;
typedef struct TurtleRGB
{
int r;
int g;
int b;
} TurtleRGB;
typedef struct Turtle
{
TurtlePoint pos;
lua_Number width;
lua_Number height;
Jan 23, 2007
Jan 23, 2007
72
lua_Number angle;
Feb 6, 2007
Feb 6, 2007
73
74
TurtlePoint points[4];
TurtleRGB pen;
Jan 23, 2007
Jan 23, 2007
75
76
int penDown;
int visible;
Feb 6, 2007
Feb 6, 2007
77
78
int recalcPoints; /* non-zero if (points) needs to be recalculated. */
int dirty; /* non-zero if turtle needs redrawing in TurtleSpace. */
Jan 23, 2007
Jan 23, 2007
79
80
81
} Turtle;
Feb 28, 2007
Feb 28, 2007
82
typedef struct TobyDebugInfo
Feb 18, 2007
Feb 18, 2007
83
84
{
const char *name;
Feb 28, 2007
Feb 28, 2007
85
const char *value;
Feb 18, 2007
Feb 18, 2007
86
int linenum;
Feb 28, 2007
Feb 28, 2007
87
} TobyDebugInfo;
Feb 18, 2007
Feb 18, 2007
88
Feb 23, 2007
Feb 23, 2007
89
Feb 6, 2007
Feb 6, 2007
90
/* !!! FIXME: comment this */
Jan 30, 2007
Jan 30, 2007
91
92
93
void TOBY_background(int *r, int *g, int *b);
Feb 6, 2007
Feb 6, 2007
94
/* !!! FIXME: comment this */
Feb 11, 2007
Feb 11, 2007
95
void TOBY_renderAllTurtles(void *udata);
Feb 6, 2007
Feb 6, 2007
96
97
Feb 28, 2007
Feb 28, 2007
98
99
100
/* !!! FIXME: comment these */
const TobyDebugInfo *TOBY_getCallstack(int *elementCount);
const TobyDebugInfo *TOBY_getVariables(int stackframe, int *elementCount);
Feb 18, 2007
Feb 18, 2007
101
102
Feb 26, 2007
Feb 26, 2007
103
104
105
106
107
108
109
110
111
112
113
114
115
/* !!! FIXME: comment all these */
void TOBY_setDelayTicksPerLine(long ms);
long TOBY_getDelayTicksPerLine(void);
void TOBY_haltProgram(void);
void TOBY_stepProgram(void);
void TOBY_continueProgram(void);
int TOBY_isPaused(void);
int TOBY_isStepping(void);
int TOBY_isRunning(void);
int TOBY_isStopping(void);
void TOBY_stepProgram(void);
Feb 23, 2007
Feb 23, 2007
116
/*
Feb 26, 2007
Feb 26, 2007
117
118
119
120
* Pause for (ms) milliseconds, calling TOBY_pumpEvents() every 50 ms or so,
* and TOBY_yieldCPU() to give up time between pumps. Returns 0 if
* TOBY_haltProgram() got called before or during the function's run,
* non-zero otherwise. Will pump the event queue at least once, even if ms
Feb 23, 2007
Feb 23, 2007
121
122
123
124
125
* is <= 0.
*/
int TOBY_delay(long ms);
126
127
128
129
/*
* This can block for a LONG time, but it will call back into your
* application with the following functions...
*/
Jan 28, 2007
Jan 28, 2007
130
void TOBY_runProgram(const char *source_code, int run_for_printing);
Feb 28, 2007
Feb 28, 2007
132
133
134
135
136
137
/* !!! FIXME: comment these. */
/* !!! FIXME: breakpoint API isn't robust, but it's all I need right now. */
void TOBY_clearAllBreakpoints(void);
int TOBY_addBreakpointLine(int line);
void TOBY_pauseReached(int line, int fullstop, int breakpoint, int pauseTicks);
138
139
140
141
142
143
144
/*
* The following are supplied by your app, and are called during the
* TOBY_runProgram() call...
*/
Jan 23, 2007
Jan 23, 2007
145
146
147
/* Set up for a new program run. This lets you prepare a backbuffer, etc. */
void TOBY_startRun(void);
Jan 24, 2007
Jan 24, 2007
149
150
151
152
/* Notify app that the program run has finished. */
void TOBY_stopRun(void);
153
154
155
156
/*
* Let UI pump its event queue. Return non-zero to keep going, zero to
* stop program execution, making TOBY_runProgram() return.
*/
Feb 26, 2007
Feb 26, 2007
157
void TOBY_pumpEvents(void);
Feb 26, 2007
Feb 26, 2007
159
160
/* !!! FIXME: comment me. */
void TOBY_putToScreen(void);
161
162
163
164
165
166
167
168
169
/*
* Put up a message box with "OK" message. Block until the user dismisses it.
* (msg) is UTF-8 encoded Unicode.
*/
void TOBY_messageBox(const char *msg);
/*
* Draw line between (x1,y1) and (x2,y2) in color r,g,b. All coordinates are
Feb 10, 2007
Feb 10, 2007
170
171
* between 0 and 999, with (0,0) being the top left of the screen and
* ...(999, 999) being to bottom right. You need to scale to the correct
172
* coordinates for your display.
Feb 10, 2007
Feb 10, 2007
173
174
*
* All lines are clipped prior to this call, so they will never be outside
Feb 10, 2007
Feb 10, 2007
175
* the 0-999 range. If they don't intersect TurtleSpace at all, this
Feb 10, 2007
Feb 10, 2007
176
* function will not be called.
Feb 6, 2007
Feb 6, 2007
178
179
void TOBY_drawLine(lua_Number x1, lua_Number y1, lua_Number x2, lua_Number y2,
int r, int g, int b);
Feb 8, 2007
Feb 8, 2007
181
182
/* !!! FIXME: comment me. */
Feb 8, 2007
Feb 8, 2007
183
184
int TOBY_drawString(lua_Number x, lua_Number y, const char *utf8str,
lua_Number angle, int r, int g, int b);
Feb 8, 2007
Feb 8, 2007
185
186
187
188
189
190
/*
* Render a turtle of size (w,h) with the center at (x,y), facing (angle).
* Angle is between 0 and 360, coordinates and sizes are in the same system
* as TOBY_drawLine().
Feb 11, 2007
Feb 11, 2007
191
* !!! FIXME: document (data).
Feb 11, 2007
Feb 11, 2007
193
void TOBY_drawTurtle(const Turtle *turtle, void *data);
Feb 6, 2007
Feb 6, 2007
194
Feb 6, 2007
Feb 6, 2007
197
* Clean up turtlespace. Blank it out to color r,g,b (0 to 255 each).
198
199
200
*/
void TOBY_cleanup(int r, int g, int b);
Jan 23, 2007
Jan 23, 2007
201
/*
Feb 23, 2007
Feb 23, 2007
202
* Get the time, in milliseconds, that the process has been running.
Jan 23, 2007
Jan 23, 2007
203
*/
Feb 23, 2007
Feb 23, 2007
204
long TOBY_getTicks(void);
Jan 23, 2007
Jan 23, 2007
205
Feb 23, 2007
Feb 23, 2007
206
207
208
209
210
/*
* Surrender the CPU to other processes for (ms) milliseconds. This doesn't
* have to exact if the OS's scheduler doesn't have good precision, and it
* can just busy loop if the OS doesn't have facilities.
* You don't have to pump the event queue here...callers are expected to
Feb 26, 2007
Feb 26, 2007
211
* alternate between this and TOBY_pumpEvents() if they are wasting time.
Feb 23, 2007
Feb 23, 2007
212
213
*/
void TOBY_yieldCPU(int ms);
Jan 23, 2007
Jan 23, 2007
214
Feb 10, 2007
Feb 10, 2007
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/*
* Clip a line defined by (*x1,*y1)-(*x2,*y2) to a rectangle of (0,0)-(w,h).
* x1, y1, x2, y2 are updated to reflect clipping. Returns zero if line
* is completely outside the rectangle, non-zero if some portion of the line
* intersects the rectangle.
*
* Frontends don't generally call this, since TOBY_drawLine() will clip the
* lines before calling the frontend (and not call it if the line isn't inside
* TurtleSpace), meaning frontends may not need to manipulate a clip region
* at all.
*/
int TOBY_clipLine(lua_Number *x1, lua_Number *y1,
lua_Number *x2, lua_Number *y2,
lua_Number w, lua_Number h);
Feb 4, 2007
Feb 4, 2007
231
extern const char *GLicense;
Feb 4, 2007
Feb 4, 2007
232
extern const char *GBuildVer;
Jan 23, 2007
Jan 23, 2007
233
234
235
236
237
#ifdef __cplusplus
}
#endif
238
239
240
#endif
/* end of toby_app.h ... */