1 /*
2 * (c) 2010 Alexander Warg <warg@os.inf.tu-dresden.de>
3 * economic rights: Technische Universität Dresden (Germany)
4 *
5 * This file is part of TUD:OS and distributed under the terms of the
6 * GNU General Public License 2.
7 * Please see the COPYING-GPL-2 file for details.
8 */
9 #pragma once
10
11
12 #include <lua.h>
13 #include <lauxlib.h>
14 #include <lualib.h>
15
16 int lua(int argc, char const* const* argv);
17
18 namespace Lua {
19
20 static char const *const package = "L4";
21 static luaL_Reg const empty_reg[] = {{NULL, NULL}};
22
23 void lua_require_module(lua_State *l, char const *name);
24
25 inline void
register_method(lua_State * l,char const * name,lua_CFunction f)26 register_method(lua_State *l, char const *name, lua_CFunction f)
27 {
28 lua_pushcfunction(l, f);
29 lua_setfield(l, -2, name);
30 }
31
32 class Lib
33 {
34 public:
35 enum Prio
36 {
37 P_cap_type,
38 P_env
39 };
40
41 explicit Lib(Prio);
42
43 virtual void init(lua_State *) = 0;
prio()44 Prio prio() const { return _prio; }
45
46 static void run_init(lua_State *);
47
48 protected:
49 ~Lib() = default;
50
51 private:
52 Prio _prio;
53 Lib *_next;
54 };
55
56 }
57
58