aboutsummaryrefslogtreecommitdiff
path: root/src/libjin-lua/embed/embed.h
blob: 0609abc2c4ee56e88c6ee33ed18a2beb56957af9 (plain)
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
#ifndef __JIN_LUA_EMBED_H__
#define __JIN_LUA_EMBED_H__
#include <cstring>

namespace JinEngine
{
    namespace Embed
    {
    
        // Embed structure.
        struct jin_Embed
        {
            const char* file;
            const unsigned char* source;
        };

        // Embed scripts.
        #include "graphics.lua.h" 
        #include "keyboard.lua.h" 
        #include "mouse.lua.h"    
        #include "app.lua.h"

        // In order.
        static const jin_Embed modules[] = {
            { "graphics.lua", graphics_lua },
            { "keyboard.lua", keyboard_lua },
            { "mouse.lua",    mouse_lua    },
            { 0,              0            }
        };

        static const jin_Embed bootscript = { "app.lua", app_lua };

        static void run(lua_State* L)
        {
            const char* file, *source;
            for (int i = 0; modules[i].file; ++i)
            {
                file = (const char*)modules[i].file;
                source = (const char*)modules[i].source;
                if (luax_loadbuffer(L, source, strlen(source), file) == 0)
                    luax_call(L, 0, 0);
            }
            file = (const char*)bootscript.source;
            source = (const char*)bootscript.source;
            if (luax_loadbuffer(L, source, strlen(source), file) == 0)
                luax_call(L, 0, 0);
        }

    } // namespace Embed
} // namespace JinEngine 

#endif // __JIN_LUA_EMBED_H__