1 /*
2  * (c) 2010 Adam Lackorzynski <adam@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 #include <l4/re/env>
10 #include <l4/sys/kip.h>
11 #include <l4/util/kip.h>
12 #include <l4/bid_config.h>
13 
14 #include <lua.h>
15 #include <lauxlib.h>
16 #include <lualib.h>
17 #include "lua.h"
18 #include "lua_cap.h"
19 
20 namespace Lua {
21 namespace {
22 
23 class Lib_info : public Lib
24 {
25 public:
Lib_info()26   Lib_info() : Lib(P_env) {}
27 
kipstr(lua_State * l)28   static int kipstr(lua_State *l)
29   {
30     const char *s = l4_kip_version_string(l4re_kip());
31     lua_pushstring(l, s);
32     return 1;
33   }
34 
archstr(lua_State * l)35   static int archstr(lua_State *l)
36   {
37     lua_pushstring(l, CONFIG_BUILD_ARCH);
38     return 1;
39   }
40 
platformstr(lua_State * l)41   static int platformstr(lua_State *l)
42   {
43     if (l4util_kip_kernel_is_ux(l4re_kip()))
44       lua_pushstring(l, "ux");
45     else
46       lua_pushstring(l, l4re_kip()->platform_info.name);
47     return 1;
48   }
49 
init(lua_State * l)50   void init(lua_State *l)
51   {
52     lua_require_module(l, package);
53     // L4.Info
54     lua_newtable(l);
55 
56     // L4.Info.Kip
57     lua_newtable(l);
58     // L4.Info.Kip.str()
59     lua_pushcfunction(l, kipstr);
60     lua_setfield(l, -2, "str");
61     lua_setfield(l, -2, "Kip");
62 
63     // L4.Info.arch()
64     lua_pushcfunction(l, archstr);
65     lua_setfield(l, -2, "arch");
66 
67     // L4.Info.platform()
68     lua_pushcfunction(l, platformstr);
69     lua_setfield(l, -2, "platform");
70 
71     lua_setfield(l, -2, "Info");
72 
73     lua_pop(l, 2);
74   }
75 };
76 
77 static Lib_info __info_lib;
78 
79 }}
80