-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
74 lines (58 loc) · 1.48 KB
/
main.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
#include <generator.h>
using namespace generator;
using namespace std;
World *generator::WORLD = NULL;
void gen_error_r(const char *mesg, const char *func, const char *file, int line)
{
fprintf(stderr, "ERROR: %s:%i %s(...): %s\n", file, line, func, mesg);
exit(EXIT_FAILURE);
}
static void print_usage(const char *name)
{
fprintf(stderr, "Usage: %s output/path objectDefinition.lua\n", name);
exit(EXIT_FAILURE);
}
std::ostream& operator<<(std::ostream& os, std::string *str)
{
os << *str;
return os;
}
int main(int argc, char *argv[])
{
if(argc <= 2)
{
print_usage(argv[0]);
}
WORLD = new World();
lua_State *state = luaL_newstate();
if(state == NULL) gen_error("creating lua state");
luaL_openlibs(state);
luaopen_process(state);
for(int i = 2; i < argc; i++)
{
int res = luaL_dofile(state, argv[i]);
WORLD->fileAdd(new std::string(argv[i]));
if(res != 0)
{
gen_error(lua_tostring(state, -1));
}
}
lua_close(state);
// Create a "contrived" example
#if 0
{
std::string *mName = new std::string("scott");
std::string *mPath = new std::string("server");
std::string *fPrefix = new std::string("us_");
std::string *funcPrefix = new std::string("");
Module *m = new Module(mName, mPath, fPrefix, funcPrefix);
WORLD->moduleAdd(mName, m);
std::string *tName = new std::string("test");
Type *t = new Type(m, tName);
m->objectAdd(tName, t);
}
#endif
if(!WORLD->generate(argv[1]))
gen_error("generating world");
return EXIT_SUCCESS;
}