-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtemplate.cpp
More file actions
64 lines (53 loc) · 1.22 KB
/
template.cpp
File metadata and controls
64 lines (53 loc) · 1.22 KB
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
// ***************************************
// * AGK - Lua *
// * *
// * By Sean Regan *
// * AGK made by The Game Creators *
// * *
// * *
// ***************************************
// Includes
#include "template.h"
// Namespace
using namespace AGK;
app App;
void app::Begin(void)
{
//Create a new lua state object
luaState = luaL_newstate();
luaL_openlibs(luaState);
//Register all of the AGK functions as Lua functions
agkLua::RegisterFunctions(luaState);
//Run the main.lua script
if (luaL_dofile(luaState, "main.lua"))
{
//Error messages
agk::Message(lua_tostring(luaState, -1));
exit(1);
}
//Call the Lua Setup function
lua_getglobal(luaState, "Setup");
if (lua_pcall(luaState, 0, 0, 0))
{
//Error handling
agk::Message(lua_tostring(luaState, -1));
exit(1);
}
}
void app::Loop(void)
{
//Call the Lua Update function
lua_getglobal(luaState, "Update");
if (lua_pcall(luaState, 0, 0, 0))
{
//Error handling
agk::Message(lua_tostring(luaState, -1));
exit(1);
}
}
void app::End(void)
{
//Clean up the Lua state
lua_close(luaState);
luaState = 0;
}