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
|
#ifndef __JIN_LUA_EMBED_H__
#define __JIN_LUA_EMBED_H__
#include <cstring>
#include "common/je_lua.h"
namespace JinEngine
{
namespace Embed
{
// Embed structure.
struct jin_Embed
{
const char* file, *source;
};
// Embed scripts.
#include "scripts/ai/state_machine.lua.h"
#include "scripts/graphics/graphics.lua.h"
#include "scripts/keyboard/keyboard.lua.h"
#include "scripts/mouse/mouse.lua.h"
#include "scripts/path/path.lua.h"
#include "scripts/app.lua.h"
// In order.
static const jin_Embed modules[] = {
// ai
{ "state_machine.lua", state_machine_lua },
// keyboard
{ "keyboard.lua", keyboard_lua },
{ "mouse.lua", mouse_lua },
{ "graphics.lua", graphics_lua },
{ "path.lua", path_lua },
{ 0, 0 }
};
static const jin_Embed bootscript = { "app.lua", app_lua };
static void run(lua_State* L)
{
jin_log_info("Load embeded scripts.");
const char* file, *source;
for (int i = 0; modules[i].file != 0; ++i)
{
file = modules[i].file;
source = modules[i].source;
jin_log_info("Embed script \"%s\".", file);
luax_clearstack(L);
if (luax_loadbuffer(L, source, strlen(source), file) == 0)
{
luax_call(L, 0, 0);
jin_log_info("Done.");
}
else
{
jin_log_error("Embed script \"%s\" failed.", file);
}
}
file = bootscript.file;
source = bootscript.source;
jin_log_info("Run boot script \"%s\".", file);
luax_clearstack(L);
if (luax_loadbuffer(L, source, strlen(source), file) == 0)
{
luax_call(L, 0, 0);
}
}
} // namespace Embed
} // namespace JinEngine
#endif // __JIN_LUA_EMBED_H__
|