-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathState.cpp
46 lines (33 loc) · 896 Bytes
/
State.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
#include "State.h"
#include "Value.h"
#include "Function.h"
#include "Stack.h"
#include "libs/BaseLib.h"
State::State():
_vm(nullptr)
{
_stack = new Stack(1000);
_global_table = new Table();
}
State::~State()
{
}
void State::registerFunc(std::string name, Fun fun)
{
_global_table->Assign(new String(name.c_str()), new NativeFunc(fun));
}
void State::registerTable(std::string name, Table* table)
{
_global_table->Assign(new String(name.c_str()), table);
}
void State::openLibs()
{
registerFunc("print", BaseLib::Print);
registerFunc("pairs", BaseLib::generatePairs);
registerFunc("ipairs", BaseLib::generateIPairs);
registerFunc("next", BaseLib::next);
registerFunc("type", BaseLib::type);
registerFunc("setmetatable", BaseLib::setmeta);
registerTable("string", BaseLib::StringLib::generateStringTable());
registerTable("math", BaseLib::MathLib::generateMathTable());
}