-
Notifications
You must be signed in to change notification settings - Fork 0
/
scene_lua.cpp
739 lines (557 loc) · 18.2 KB
/
scene_lua.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
//
// Introduction to Computer Graphics
//
// scene_lua.cpp
//
// Everything that's needed to parse a scene file using Lua.
// You don't necessarily have to understand exactly everything that
// goes on here, although it will be useful to have a reasonable idea
// if you wish to add new commands to the scene format.
//
// Lua interfaces with C/C++ using a special stack. Everytime you want
// to get something from lua, or pass something back to lua (e.g. a
// return value), you need to use this stack. Thus, most of the lua_
// and luaL_ functions actually manipulate the stack. All the
// functions beginning with "lua_" are part of the Lua C API itself,
// whereas the "luaL_" functions belong to a library of useful
// functions on top of that called lauxlib.
//
// This file consists of a bunch of C function declarations which
// implement functions callable from Lua. There are also two tables
// used to set up the interface between Lua and these functions, and
// the main "driver" function, import_lua, which calls the lua
// interpreter and sets up all the state.
//
// Note that each of the function declarations follow the same format:
// they take as their only argument the current state of the lua
// interpreter, and return the number of values returned back to lua.
//
// For more information see the book "Programming In Lua," available
// online at http://www.lua.org/pil/, and of course the Lua reference
// manual at http://www.lua.org/manual/5.0/.
//
// http://lua-users.org/wiki/LauxLibDocumentation provides a useful
// documentation of the "lauxlib" functions (beginning with luaL_).
//
// -- University of Waterloo Computer Graphics Lab 2005
#include "scene_lua.hpp"
#include <iostream>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <vector>
#include <map>
#include "lua488.hpp"
#include "Light.hpp"
#include "Mesh.hpp"
#include "GeometryNode.hpp"
#include "JointNode.hpp"
#include "Primitive.hpp"
#include "Material.hpp"
#include "PhongMaterial.hpp"
#include "BumpMap.hpp"
#include "Texture.hpp"
#include "A5.hpp"
typedef std::map<std::string,Mesh*> MeshMap;
static MeshMap mesh_map;
// Uncomment the following line to enable debugging messages
// #define GRLUA_ENABLE_DEBUG
#ifdef GRLUA_ENABLE_DEBUG
# define GRLUA_DEBUG(x) do { std::cerr << x << std::endl; } while (0)
# define GRLUA_DEBUG_CALL do { std::cerr << __FUNCTION__ << std::endl; } while (0)
#else
# define GRLUA_DEBUG(x) do { } while (0)
# define GRLUA_DEBUG_CALL do { } while (0)
#endif
// You may wonder, for the following types, why we use special "_ud"
// types instead of, for example, just allocating SceneNodes directly
// from lua. Part of the answer is that Lua is a C api. It doesn't
// call any constructors or destructors for you, so it's easier if we
// let it just allocate a pointer for the node, and handle
// allocation/deallocation of the node itself. Another (perhaps more
// important) reason is that we will want SceneNodes to stick around
// even after lua is done with them, after all, we want to pass them
// back to the program. If we let Lua allocate SceneNodes directly,
// we'd lose them all when we are done parsing the script. This way,
// we can easily keep around the data, all we lose is the extra
// pointers to it.
// The "userdata" type for a node. Objects of this type will be
// allocated by Lua to represent nodes.
struct gr_node_ud {
SceneNode* node;
};
// The "userdata" type for a material. Objects of this type will be
// allocated by Lua to represent materials.
struct gr_material_ud {
Material* material;
};
// The "userdata" type for a light. Objects of this type will be
// allocated by Lua to represent lights.
struct gr_light_ud {
Light* light;
};
// Useful function to retrieve and check an n-tuple of numbers.
template<typename T>
void get_tuple(lua_State* L, int arg, T* data, int n)
{
luaL_checktype(L, arg, LUA_TTABLE);
luaL_argcheck(L, lua_rawlen(L, arg) == n, arg, "N-tuple expected");
for (int i = 1; i <= n; i++) {
lua_rawgeti(L, arg, i);
data[i - 1] = luaL_checknumber(L, -1);
lua_pop(L, 1);
}
}
// Create a node
extern "C"
int gr_node_cmd(lua_State* L)
{
GRLUA_DEBUG_CALL;
gr_node_ud* data = (gr_node_ud*)lua_newuserdata(L, sizeof(gr_node_ud));
data->node = 0;
const char* name = luaL_checkstring(L, 1);
data->node = new SceneNode(name);
luaL_getmetatable(L, "gr.node");
lua_setmetatable(L, -2);
return 1;
}
// Create a joint node
extern "C"
int gr_joint_cmd(lua_State* L)
{
GRLUA_DEBUG_CALL;
gr_node_ud* data = (gr_node_ud*)lua_newuserdata(L, sizeof(gr_node_ud));
data->node = 0;
const char* name = luaL_checkstring(L, 1);
JointNode* node = new JointNode(name);
double x[3], y[3];
get_tuple(L, 2, x, 3);
get_tuple(L, 3, y, 3);
node->set_joint_x(x[0], x[1], x[2]);
node->set_joint_y(y[0], y[1], y[2]);
data->node = node;
luaL_getmetatable(L, "gr.node");
lua_setmetatable(L, -2);
return 1;
}
// Create a sphere node
extern "C"
int gr_sphere_cmd(lua_State* L)
{
GRLUA_DEBUG_CALL;
gr_node_ud* data = (gr_node_ud*)lua_newuserdata(L, sizeof(gr_node_ud));
data->node = 0;
const char* name = luaL_checkstring(L, 1);
data->node = new GeometryNode( name, new Sphere() );
luaL_getmetatable(L, "gr.node");
lua_setmetatable(L, -2);
return 1;
}
// Create a cube node
extern "C"
int gr_cube_cmd(lua_State* L)
{
GRLUA_DEBUG_CALL;
gr_node_ud* data = (gr_node_ud*)lua_newuserdata(L, sizeof(gr_node_ud));
data->node = 0;
const char* name = luaL_checkstring(L, 1);
data->node = new GeometryNode(name, new Cube());
luaL_getmetatable(L, "gr.node");
lua_setmetatable(L, -2);
return 1;
}
// Create a cylinder node
extern "C"
int gr_cylinder_cmd(lua_State* L)
{
GRLUA_DEBUG_CALL;
gr_node_ud* data = (gr_node_ud*)lua_newuserdata(L, sizeof(gr_node_ud));
data->node = 0;
const char* name = luaL_checkstring(L, 1);
data->node = new GeometryNode(name, new Cylinder());
luaL_getmetatable(L, "gr.node");
lua_setmetatable(L, -2);
return 1;
}
// Create a cone node
extern "C"
int gr_cone_cmd(lua_State* L)
{
GRLUA_DEBUG_CALL;
gr_node_ud* data = (gr_node_ud*)lua_newuserdata(L, sizeof(gr_node_ud));
data->node = 0;
const char* name = luaL_checkstring(L, 1);
data->node = new GeometryNode(name, new Cone());
luaL_getmetatable(L, "gr.node");
lua_setmetatable(L, -2);
return 1;
}
// Create a cone node
extern "C"
int gr_torus_cmd(lua_State* L)
{
GRLUA_DEBUG_CALL;
gr_node_ud* data = (gr_node_ud*)lua_newuserdata(L, sizeof(gr_node_ud));
data->node = 0;
const char* name = luaL_checkstring(L, 1);
data->node = new GeometryNode(name, new Torus());
luaL_getmetatable(L, "gr.node");
lua_setmetatable(L, -2);
return 1;
}
// Create a non-hierarchical sphere node
extern "C"
int gr_nh_sphere_cmd(lua_State* L)
{
GRLUA_DEBUG_CALL;
gr_node_ud* data = (gr_node_ud*)lua_newuserdata(L, sizeof(gr_node_ud));
data->node = 0;
const char* name = luaL_checkstring(L, 1);
glm::vec3 pos;
get_tuple(L, 2, &pos[0], 3);
double radius = luaL_checknumber(L, 3);
data->node = new GeometryNode(name, new NonhierSphere(pos, radius));
luaL_getmetatable(L, "gr.node");
lua_setmetatable(L, -2);
return 1;
}
// Create a non-hierarchical box node
extern "C"
int gr_nh_box_cmd(lua_State* L)
{
GRLUA_DEBUG_CALL;
gr_node_ud* data = (gr_node_ud*)lua_newuserdata(L, sizeof(gr_node_ud));
data->node = 0;
const char* name = luaL_checkstring(L, 1);
glm::vec3 pos;
get_tuple(L, 2, &pos[0], 3);
double size = luaL_checknumber(L, 3);
data->node = new GeometryNode(name, new NonhierBox(pos, size));
luaL_getmetatable(L, "gr.node");
lua_setmetatable(L, -2);
return 1;
}
// Create a polygonal mesh node
extern "C"
int gr_mesh_cmd(lua_State* L)
{
GRLUA_DEBUG_CALL;
gr_node_ud* data = (gr_node_ud*)lua_newuserdata(L, sizeof(gr_node_ud));
data->node = 0;
const char* name = luaL_checkstring(L, 1);
const char* obj_fname = luaL_checkstring(L, 2);
std::string sfname( obj_fname );
// Use a dictionary structure to make sure every mesh is loaded
// at most once.
auto i = mesh_map.find( sfname );
Mesh *mesh = nullptr;
if( i == mesh_map.end() ) {
mesh = new Mesh( obj_fname );
} else {
mesh = i->second;
}
data->node = new GeometryNode( name, mesh );
luaL_getmetatable(L, "gr.node");
lua_setmetatable(L, -2);
return 1;
}
// Make a point light
extern "C"
int gr_light_cmd(lua_State* L)
{
GRLUA_DEBUG_CALL;
gr_light_ud* data = (gr_light_ud*)lua_newuserdata(L, sizeof(gr_light_ud));
data->light = 0;
Light l;
double col[3];
get_tuple(L, 1, &l.position[0], 3);
get_tuple(L, 2, col, 3);
get_tuple(L, 3, l.falloff, 3);
l.colour = glm::vec3(col[0], col[1], col[2]);
data->light = new Light(l);
luaL_newmetatable(L, "gr.light");
lua_setmetatable(L, -2);
return 1;
}
// Make a rectangular area light
extern "C"
int gr_arealight_cmd(lua_State* L)
{
GRLUA_DEBUG_CALL;
gr_light_ud* data = (gr_light_ud*)lua_newuserdata(L, sizeof(gr_light_ud));
data->light = 0;
AreaLight l;
double col[3];
get_tuple(L, 1, &l.position[0], 3);
get_tuple(L, 2, col, 3);
get_tuple(L, 3, l.falloff, 3);
double corner[3];
for(int i=0; i<4; i++){
get_tuple(L, 4+i, corner, 3);
l.corner[i] = glm::vec3(corner[0], corner[1], corner[2]);
}
l.colour = glm::vec3(col[0], col[1], col[2]);
data->light = new AreaLight(l);
data->light->preprocess();
luaL_newmetatable(L, "gr.light");
lua_setmetatable(L, -2);
return 1;
}
// Render a scene
extern "C"
int gr_render_cmd(lua_State* L)
{
GRLUA_DEBUG_CALL;
gr_node_ud* root = (gr_node_ud*)luaL_checkudata(L, 1, "gr.node");
luaL_argcheck(L, root != 0, 1, "Root node expected");
const char* filename = luaL_checkstring(L, 2);
int width = luaL_checknumber(L, 3);
int height = luaL_checknumber(L, 4);
glm::vec3 eye;
glm::vec3 view, up;
get_tuple(L, 5, &eye[0], 3);
get_tuple(L, 6, &view[0], 3);
get_tuple(L, 7, &up[0], 3);
double fov = luaL_checknumber(L, 8);
double ambient_data[3];
get_tuple(L, 9, ambient_data, 3);
glm::vec3 ambient(ambient_data[0], ambient_data[1], ambient_data[2]);
luaL_checktype(L, 10, LUA_TTABLE);
int light_count = int(lua_rawlen(L, 10));
luaL_argcheck(L, light_count >= 1, 10, "Tuple of lights expected");
std::list<Light*> lights;
for (int i = 1; i <= light_count; i++) {
lua_rawgeti(L, 10, i);
gr_light_ud* ldata = (gr_light_ud*)luaL_checkudata(L, -1, "gr.light");
luaL_argcheck(L, ldata != 0, 10, "Light expected");
lights.push_back(ldata->light);
lua_pop(L, 1);
}
Image im( width, height);
A4_Render(root->node, im, eye, view, up, fov, ambient, lights);
im.savePng( filename );
return 0;
}
// Create a material
extern "C"
int gr_material_cmd(lua_State* L)
{
GRLUA_DEBUG_CALL;
gr_material_ud* data = (gr_material_ud*)lua_newuserdata(L, sizeof(gr_material_ud));
data->material = 0;
double kd[3], ks[3];
get_tuple(L, 1, kd, 3);
get_tuple(L, 2, ks, 3);
double shininess = luaL_checknumber(L, 3);
double refractIdx = luaL_checknumber(L, 4);
double glossiness = luaL_checknumber(L, 5);
double reflectance = luaL_checknumber(L, 6);
data->material = new PhongMaterial(glm::vec3(kd[0], kd[1], kd[2]),
glm::vec3(ks[0], ks[1], ks[2]),
shininess,
refractIdx,
glossiness,
reflectance);
luaL_newmetatable(L, "gr.material");
lua_setmetatable(L, -2);
return 1;
}
// Add a child to a node
extern "C"
int gr_node_add_child_cmd(lua_State* L)
{
GRLUA_DEBUG_CALL;
gr_node_ud* selfdata = (gr_node_ud*)luaL_checkudata(L, 1, "gr.node");
luaL_argcheck(L, selfdata != 0, 1, "Node expected");
SceneNode* self = selfdata->node;
gr_node_ud* childdata = (gr_node_ud*)luaL_checkudata(L, 2, "gr.node");
luaL_argcheck(L, childdata != 0, 2, "Node expected");
SceneNode* child = childdata->node;
self->add_child(child);
return 0;
}
// Set a node's material
extern "C"
int gr_node_set_material_cmd(lua_State* L)
{
GRLUA_DEBUG_CALL;
gr_node_ud* selfdata = (gr_node_ud*)luaL_checkudata(L, 1, "gr.node");
luaL_argcheck(L, selfdata != 0, 1, "Node expected");
GeometryNode* self = dynamic_cast<GeometryNode*>(selfdata->node);
luaL_argcheck(L, self != 0, 1, "Geometry node expected");
gr_material_ud* matdata = (gr_material_ud*)luaL_checkudata(L, 2, "gr.material");
luaL_argcheck(L, matdata != 0, 2, "Material expected");
Material* material = matdata->material;
self->setMaterial(material);
return 0;
}
// Set a node's texture
extern "C"
int gr_node_set_texture_cmd(lua_State* L)
{
GRLUA_DEBUG_CALL;
gr_node_ud* selfdata = (gr_node_ud*)luaL_checkudata(L, 1, "gr.node");
luaL_argcheck(L, selfdata != 0, 1, "Node expected");
GeometryNode* self = dynamic_cast<GeometryNode*>(selfdata->node);
luaL_argcheck(L, self != 0, 1, "Geometry node expected");
std::string file = luaL_checkstring(L, 2);
Texture *tex = new Texture(file);
self->tex = tex;
return 0;
}
// Set a node's bump
extern "C"
int gr_node_set_bump_cmd(lua_State* L)
{
GRLUA_DEBUG_CALL;
gr_node_ud* selfdata = (gr_node_ud*)luaL_checkudata(L, 1, "gr.node");
luaL_argcheck(L, selfdata != 0, 1, "Node expected");
GeometryNode* self = dynamic_cast<GeometryNode*>(selfdata->node);
luaL_argcheck(L, self != 0, 1, "Geometry node expected");
std::string file = luaL_checkstring(L, 2);
BumpMap *bump = new BumpMap(file);
bump->hasBumpMap = true;
self->m_bump = bump;
return 0;
}
// Add a scaling transformation to a node.
extern "C"
int gr_node_scale_cmd(lua_State* L)
{
GRLUA_DEBUG_CALL;
gr_node_ud* selfdata = (gr_node_ud*)luaL_checkudata(L, 1, "gr.node");
luaL_argcheck(L, selfdata != 0, 1, "Node expected");
SceneNode* self = selfdata->node;
double values[3];
for (int i = 0; i < 3; i++) {
values[i] = luaL_checknumber(L, i + 2);
}
self->scale(glm::vec3(values[0], values[1], values[2]));
return 0;
}
// Add a translation to a node.
extern "C"
int gr_node_translate_cmd(lua_State* L)
{
GRLUA_DEBUG_CALL;
gr_node_ud* selfdata = (gr_node_ud*)luaL_checkudata(L, 1, "gr.node");
luaL_argcheck(L, selfdata != 0, 1, "Node expected");
SceneNode* self = selfdata->node;
double values[3];
for (int i = 0; i < 3; i++) {
values[i] = luaL_checknumber(L, i + 2);
}
self->translate(glm::vec3(values[0], values[1], values[2]));
return 0;
}
// Rotate a node.
extern "C"
int gr_node_rotate_cmd(lua_State* L)
{
GRLUA_DEBUG_CALL;
gr_node_ud* selfdata = (gr_node_ud*)luaL_checkudata(L, 1, "gr.node");
luaL_argcheck(L, selfdata != 0, 1, "Node expected");
SceneNode* self = selfdata->node;
const char* axis_string = luaL_checkstring(L, 2);
luaL_argcheck(L, axis_string
&& std::strlen(axis_string) == 1, 2, "Single character expected");
char axis = std::tolower(axis_string[0]);
luaL_argcheck(L, axis >= 'x' && axis <= 'z', 2, "Axis must be x, y or z");
double angle = luaL_checknumber(L, 3);
self->rotate(axis, angle);
return 0;
}
// Garbage collection function for lua.
extern "C"
int gr_node_gc_cmd(lua_State* L)
{
GRLUA_DEBUG_CALL;
gr_node_ud* data = (gr_node_ud*)luaL_checkudata(L, 1, "gr.node");
luaL_argcheck(L, data != 0, 1, "Node expected");
// Note that we don't delete the node here. This is because we still
// want the scene to be around when we close the lua interpreter,
// but at that point everything will be garbage collected.
//
// If data->node happened to be a reference-counting pointer, this
// will in fact just decrease lua's reference to it, so it's not a
// bad thing to include this line.
data->node = 0;
return 0;
}
// This is where all the "global" functions in our library are
// declared.
// If you want to add a new non-member function, add it here.
static const luaL_Reg grlib_functions[] = {
{"node", gr_node_cmd},
{"sphere", gr_sphere_cmd},
{"joint", gr_joint_cmd},
{"material", gr_material_cmd},
// New for assignment 4
{"cube", gr_cube_cmd},
{"cylinder", gr_cylinder_cmd},
{"cone", gr_cone_cmd},
{"torus", gr_torus_cmd},
{"nh_sphere", gr_nh_sphere_cmd},
{"nh_box", gr_nh_box_cmd},
{"mesh", gr_mesh_cmd},
{"light", gr_light_cmd},
{"arealight", gr_arealight_cmd},
{"render", gr_render_cmd},
{0, 0}
};
// This is where all the member functions for "gr.node" objects are
// declared. Since all the other objects (e.g. materials) are so
// simple, we only really need to make member functions for nodes.
//
// If you want to add a new member function for gr.node, add it
// here.
//
// We could have used inheritance in lua to match the inheritance
// between different node types, but it's easier to just give all
// nodes the same Lua type and then do any additional type checking in
// the appropriate member functions (e.g. gr_node_set_material_cmd
// ensures that the node is a GeometryNode, see above).
static const luaL_Reg grlib_node_methods[] = {
{"__gc", gr_node_gc_cmd},
{"add_child", gr_node_add_child_cmd},
{"set_material", gr_node_set_material_cmd},
{"set_bump", gr_node_set_bump_cmd},
{"set_texture", gr_node_set_texture_cmd},
{"scale", gr_node_scale_cmd},
{"rotate", gr_node_rotate_cmd},
{"translate", gr_node_translate_cmd},
{"render", gr_render_cmd},
{0, 0}
};
// This function calls the lua interpreter to define the scene and
// raytrace it as appropriate.
bool run_lua(const std::string& filename)
{
GRLUA_DEBUG("Importing scene from " << filename);
// Start a lua interpreter
lua_State* L = luaL_newstate();
GRLUA_DEBUG("Loading base libraries");
// Load some base library
luaL_openlibs(L);
GRLUA_DEBUG("Setting up our functions");
// Set up the metatable for gr.node
luaL_newmetatable(L, "gr.node");
lua_pushstring(L, "__index");
lua_pushvalue(L, -2);
lua_settable(L, -3);
// Load the gr.node methods
luaL_setfuncs( L, grlib_node_methods, 0 );
// Load the gr functions
luaL_setfuncs(L, grlib_functions, 0);
lua_setglobal(L, "gr");
GRLUA_DEBUG("Parsing the scene");
// Now parse the actual scene
if (luaL_loadfile(L, filename.c_str()) || lua_pcall(L, 0, 0, 0)) {
std::cerr << "Error loading " << filename << ": " << lua_tostring(L, -1) << std::endl;
return false;
}
GRLUA_DEBUG("Closing the interpreter");
// Close the interpreter, free up any resources not needed
lua_close(L);
return true;
}