Lines Matching refs:l
21 get_cap_cast_table(lua_State *l) in get_cap_cast_table() argument
23 lua_getglobal(l, package); in get_cap_cast_table()
24 lua_getfield(l, LUA_REGISTRYINDEX, "L4::Ned::TYPES"); in get_cap_cast_table()
25 lua_remove(l, -2); in get_cap_cast_table()
33 Cap::create_class(lua_State *l, Register_methods *rm, char const *type) in create_class() argument
35 lua_newtable(l); in create_class()
36 rm(l); in create_class()
37 lua_pushstring(l, type); in create_class()
38 lua_setfield(l, -2, "_CLASS_NAME"); in create_class()
42 Cap::get_class(lua_State *l) in get_class() argument
44 get_cap_cast_table(l); in get_class()
45 lua_getfield(l, -1, "void"); in get_class()
46 lua_remove(l, -2); in get_class()
50 is_valid(lua_State *l) in is_valid() argument
52 Cap *n = check_cap(l, 1); in is_valid()
53 lua_pushboolean(l, n && n->cap<void>().is_valid()); in is_valid()
58 gc_cap(lua_State *l) in gc_cap() argument
60 Lua::Cap *n = check_cap(l, 1); in gc_cap()
67 tostring(lua_State *l) in tostring() argument
69 Lua::Cap *n = check_cap(l, 1); in tostring()
70 lua_getuservalue(l, 1); in tostring()
71 lua_rawgeti(l, -1, 0); in tostring()
73 if (!lua_isnil(l, -1)) in tostring()
75 lua_getfield(l, -1, "_CLASS_NAME"); in tostring()
76 type = lua_tostring(l, -1); in tostring()
80 lua_pushfstring(l, "L4::Cap<%s>[%p] r=%p f=%p", type, in tostring()
84 lua_pushfstring(l, "L4::Cap<%s>::Invalid", type); in tostring()
89 __set_rights(lua_State *l, unsigned r) in __set_rights() argument
91 Lua::Cap *n = check_cap(l, 1); in __set_rights()
93 lua_pushvalue(l, 1); in __set_rights()
96 Lua::Cap *t = n->clone(l); in __set_rights()
98 lua_getuservalue(l, 1); in __set_rights()
99 lua_setuservalue(l, -2); in __set_rights()
107 __set_mode_call(lua_State *l) in __set_mode_call() argument
110 if (lua_gettop(l) >= 2 && !lua_isnil(l, 2)) in __set_mode_call()
113 if (lua_isnumber(l, 2)) in __set_mode_call()
114 rights = lua_tointeger(l, 2); in __set_mode_call()
117 for (char const *r = lua_tostring(l, 2); *r; ++r) in __set_mode_call()
136 __set_rights(l, rights); in __set_mode_call()
140 c = check_cap(l, 1); in __set_mode_call()
142 lua_pushinteger(l, c->rights()); in __set_mode_call()
149 __full(lua_State *l) in __full() argument
151 __set_rights(l, 0xef); in __full()
157 Cap::find_dynamic_type(lua_State *l) const in find_dynamic_type()
173 get_method_table(l, name.data); in find_dynamic_type()
174 if (lua_isnil(l, -1)) in find_dynamic_type()
176 lua_pop(l, -1); in find_dynamic_type()
184 Cap::index(lua_State *l) const in index()
186 get_method_table(l, "void"); // push table in index()
187 lua_pushvalue(l, 2); // push key in index()
188 lua_gettable(l, -2); in index()
190 if (!lua_isnil(l, -1)) in index()
193 lua_pop(l, 2); // pop nil result, and method table in index()
195 lua_getuservalue(l, 1); in index()
196 lua_rawgeti(l, -1, 0); in index()
197 if (lua_isnil(l, -1)) in index()
199 lua_pop(l, 1); in index()
200 if (!find_dynamic_type(l)) in index()
203 lua_pushvalue(l, -1); // keep table after set in index()
204 lua_rawseti(l, -3, 0); in index()
207 lua_pushvalue(l, 2); // push key in index()
208 lua_gettable(l, -2); in index()
212 static int __index(lua_State *l) in __index() argument
214 Lua::Cap *n = Lua::check_cap(l, 1); in __index()
215 return n->index(l); in __index()
219 void init_cap_metatable(lua_State *l) in init_cap_metatable() argument
221 Lua::register_method(l, "__gc", gc_cap); in init_cap_metatable()
222 Lua::register_method(l, "__tostring", tostring); in init_cap_metatable()
223 Lua::register_method(l, "__index", __index); in init_cap_metatable()
227 void push_cap_metatable(lua_State *l) in push_cap_metatable() argument
229 if (luaL_newmetatable(l, CAP_TYPE)) in push_cap_metatable()
230 init_cap_metatable(l); in push_cap_metatable()
233 void set_cap_metatable(lua_State *l) in set_cap_metatable() argument
235 push_cap_metatable(l); in set_cap_metatable()
236 lua_setmetatable(l, -2); in set_cap_metatable()
240 Cap::get_method_table(lua_State *l, char const *typ) const in get_method_table() argument
242 get_cap_cast_table(l); in get_method_table()
243 lua_getfield(l, -1, typ /*type()*/); in get_method_table()
244 lua_remove(l, -2); in get_method_table()
249 if (luaL_newmetatable(l, type()))
251 luaL_register(l, NULL, l4_cap_class);
259 push_void_cap(lua_State *l) in push_void_cap() argument
261 Cap *c = new (lua_newuserdata(l, sizeof(Cap))) Cap(); in push_void_cap()
262 set_cap_metatable(l); in push_void_cap()
263 lua_newtable(l); in push_void_cap()
264 lua_setuservalue(l, -2); in push_void_cap()
270 push_new_cap(lua_State *l, bool void_cap) in push_new_cap() argument
272 int const frame = lua_gettop(l); in push_new_cap()
273 get_cap_cast_table(l); in push_new_cap()
274 lua_pushvalue(l, frame); in push_new_cap()
276 lua_remove(l, frame); in push_new_cap()
277 lua_gettable(l, frame); in push_new_cap()
278 lua_remove(l, frame); // discard cast table in push_new_cap()
284 if ((found_type = !lua_isnil(l, frame)) || void_cap) in push_new_cap()
285 nc = push_void_cap(l); // cap at frame + 1 in push_new_cap()
289 lua_getuservalue(l, frame + 1); in push_new_cap()
290 lua_pushvalue(l, frame); in push_new_cap()
291 lua_rawseti(l, -2, 0); in push_new_cap()
292 lua_pop(l, 1); // pop env table in push_new_cap()
295 lua_remove(l, frame); // cap or nothing at frame in push_new_cap()
300 register_cap(lua_State *l, char const *name, L4::Cap<void> i, long proto) in register_cap() argument
302 lua_pushinteger(l, proto); in register_cap()
303 Cap *c = push_new_cap(l, true); in register_cap()
306 lua_setfield(l, -2, name); in register_cap()
310 __cast(lua_State *l) in __cast() argument
312 if (lua_gettop(l) > 2) in __cast()
313 luaL_error(l, "too many arguments to L4.cast (expected 2: type and cap)"); in __cast()
315 if (lua_isfunction(l, 2)) in __cast()
316 lua_call(l, 0, 1); in __cast()
318 Cap *c = check_cap(l, 2); in __cast()
319 lua_pushvalue(l, 1); in __cast()
320 Cap *nc = push_new_cap(l, false); in __cast()
327 lua_pushnil(l); in __cast()
333 init_lua_cap(lua_State *l) in init_lua_cap() argument
341 Lua::lua_require_module(l, package); in init_lua_cap()
342 luaL_setfuncs(l, _cast_f, 0); in init_lua_cap()
343 lua_newtable(l); in init_lua_cap()
344 lua_pushvalue(l, -1); in init_lua_cap()
345 lua_setfield(l, -3, CAST_TABLE); in init_lua_cap()
346 lua_setfield(l, LUA_REGISTRYINDEX, "L4::Ned::TYPES"); in init_lua_cap()
348 get_cap_cast_table(l); in init_lua_cap()
349 Cap::create_class(l, Cap::register_methods, "void"); in init_lua_cap()
350 lua_setfield(l, -2, "void"); in init_lua_cap()
351 lua_pop(l, 2); in init_lua_cap()
355 Cap::register_methods(lua_State *l) in register_methods() argument
366 luaL_setfuncs(l, l4_cap_class, 0); in register_methods()