aboutsummaryrefslogtreecommitdiff
path: root/src/lua/embed/embed.h
blob: cde2ba442b9b33f7b0ee5bb5b9e6f3da5c0e4c6b (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
#ifndef __JIN_LUA_EMBED_H
#define __JIN_LUA_EMBED_H
#include <cstring>

namespace JinEngine
{
namespace embed
{
    
#define embed(L, script, name)\
    if(luax_loadbuffer(L, script, strlen(script), name) == 0)\
        lua_call(L, 0, 0);

    /**
    * embed structure. 
    */
    struct jin_Embed
    {
        const char* file, *source;
    };

    static void boot(lua_State* L)
    {
        // embed scripts 
        #include "graphics.lua.h" 
        #include "keyboard.lua.h" 
        #include "mouse.lua.h"    
        #include "boot.lua.h"     

        // in order
        const jin_Embed scripts[] = {
            { "graphics.lua", graphics_lua },
            { "keyboard.lua", keyboard_lua },
            { "mouse.lua",    mouse_lua    },
            { "boot.lua",     boot_lua     },
            { 0,              0            }
        };

        for (int i = 0; scripts[i].file; ++i)
            embed(L, scripts[i].source, scripts[i].file);
    }

} // embed
} // JinEngine 

#endif