]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ned/server/src/lua_info.cc
00800527736d612a3a787573469d0e86afb37086
[l4.git] / l4 / pkg / ned / server / src / lua_info.cc
1 #include <l4/re/env>
2 #include <l4/sys/kip.h>
3 #include <l4/util/kip.h>
4
5 #include <lua.h>
6 #include <lauxlib.h>
7 #include <lualib.h>
8 #include "lua.h"
9 #include "lua_cap.h"
10
11 namespace Lua {
12 namespace {
13
14 class Lib_info : public Lib
15 {
16 public:
17   Lib_info() : Lib(P_env) {}
18
19   static int kipstr(lua_State *l)
20   {
21     const char *s = l4_kip_version_string(l4re_kip());
22     lua_pushstring(l, s);
23     return 1;
24   }
25
26   static int archstr(lua_State *l)
27   {
28 #if defined(ARCH_x86)
29     const char *s = "x86";
30 #elif defined(ARCH_amd64)
31     const char *s = "amd64";
32 #elif defined(ARCH_arm)
33     const char *s = "arm";
34 #elif defined(ARCH_ppc32)
35     const char *s = "ppc32";
36 #else
37 #error Add your arch-string!
38 #endif
39     lua_pushstring(l, s);
40     return 1;
41   }
42
43   static int platformstr(lua_State *l)
44   {
45     if (l4util_kip_kernel_is_ux(l4re_kip()))
46       lua_pushstring(l, "ux");
47     else
48       lua_pushstring(l, l4re_kip()->platform_info.name);
49     return 1;
50   }
51
52   void init(lua_State *l)
53   {
54     luaL_register(l, package, empty_reg);
55     // L4.Info
56     lua_newtable(l);
57
58     // L4.Info.Kip
59     lua_newtable(l);
60     // L4.Info.Kip.str()
61     lua_pushcfunction(l, kipstr);
62     lua_setfield(l, -2, "str");
63     lua_setfield(l, -2, "Kip");
64
65     // L4.Info.arch()
66     lua_pushcfunction(l, archstr);
67     lua_setfield(l, -2, "arch");
68
69     // L4.Info.platform()
70     lua_pushcfunction(l, platformstr);
71     lua_setfield(l, -2, "platform");
72
73     lua_setfield(l, -2, "Info");
74
75     lua_pop(l, 2);
76   }
77 };
78
79 static Lib_info __info_lib;
80
81 }}