summaryrefslogtreecommitdiff
path: root/core/src/xmake/engine.h
blob: 04ef958d93d8c4f33212bddfdd20eb0b6cbbf990 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*!A cross-platform build utility based on Lua
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Copyright (C) 2015-present, Xmake Open Source Community.
 *
 * @author      ruki
 * @file        engine.h
 *
 */
#ifndef XM_ENGINE_H
#define XM_ENGINE_H

/* //////////////////////////////////////////////////////////////////////////////////////
 * includes
 */
#include "prefix.h"

/* //////////////////////////////////////////////////////////////////////////////////////
 * extern
 */
__tb_extern_c_enter__

/* //////////////////////////////////////////////////////////////////////////////////////
 * types
 */

/// the xmake engine type
typedef struct {tb_int_t dummy;} const* xm_engine_ref_t;

/// the lni initializer callback type
typedef tb_void_t (*xm_engine_lni_initalizer_cb_t)(xm_engine_ref_t engine, lua_State* lua);

/* //////////////////////////////////////////////////////////////////////////////////////
 * interfaces
 */

/*! init the engine
 *
 * @param name              the engine name
 * @param lni_initalizer    the lni initializer
 *
 * @return                  the engine
 */
xm_engine_ref_t             xm_engine_init(tb_char_t const* name, xm_engine_lni_initalizer_cb_t lni_initalizer);

/*! exit the engine
 *
 * @param engine            the engine
 */
tb_void_t                   xm_engine_exit(xm_engine_ref_t engine);

/*! do the main entry of the engine
 *
 * @param engine            the engine
 * @param argc              the argument count of the console
 * @param argv              the argument list of the console
 * @param taskargv          the argument list of sub-task, e.g. taskargv(lua -vD lua.main) for xmake lua -vD lua.main arg1 arg2 ..
 *
 * @return                  the error code of main()
 */
tb_int_t                    xm_engine_main(xm_engine_ref_t engine, tb_int_t argc, tb_char_t** argv, tb_char_t** taskargv);

/*! register lni modules in the engine, @note we need to call it in lni_initalizer()
 *
 * @param engine            the engine
 * @param module            the lni module name
 * @param funcs             the lni module functions
 */
tb_void_t                   xm_engine_register(xm_engine_ref_t engine, tb_char_t const* module, luaL_Reg const funcs[]);

/*! add the embed files
 *
 * @param engine            the engine
 * @param data              the embedfiles data
 * @param size              the data size
 */
tb_void_t                   xm_engine_add_embedfiles(xm_engine_ref_t engine, tb_byte_t const* data, tb_size_t size);

/* get lua state from engine
 *
 * @param engine            the engine
 *
 * @return                  the lua state
 */
lua_State*                  xm_engine_lua(xm_engine_ref_t engine);

/* get poller from engine
 *
 * @param engine            the engine
 *
 * @return                  the poller
 */
tb_poller_ref_t             xm_engine_poller(xm_engine_ref_t engine);

/*! run main entry of the engine singleton
 *
 * @param name              the engine name
 * @param argc              the argument count of the console
 * @param argv              the argument list of the console
 * @param taskargv          the argument list of sub-task, e.g. taskargv(lua -vD lua.main) for xmake lua -vD lua.main arg1 arg2 ..
 * @param lni_initalizer    the lni initializer
 *
 * @return                  the error code of main()
 */
tb_int_t                    xm_engine_run(tb_char_t const* name, tb_int_t argc, tb_char_t** argv, tb_char_t** taskargv, xm_engine_lni_initalizer_cb_t lni_initalizer);

/*! get engine from the given lua state
 *
 * @param lua               the lua state
 *
 * @return                  the engine
 */
xm_engine_ref_t             xm_engine_get(lua_State* lua);

/* //////////////////////////////////////////////////////////////////////////////////////
 * extern
 */
__tb_extern_c_leave__

#endif