2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include "apr_tables.h"
26 * make a userdata out of a C pointer, and vice versa
27 * instead of using lightuserdata
29 #ifndef lua_boxpointer
30 #define lua_boxpointer(L,u) (*(void **)(lua_newuserdata(L, sizeof(void *))) = (u))
31 #define lua_unboxpointer(L,i) (*(void **)(lua_touserdata(L, i)))
35 apr_table_t
*check_apr_table(lua_State
*L
, int index
)
38 luaL_checkudata(L
, index
, "Apr.Table");
39 t
= (apr_table_t
*) lua_unboxpointer(L
, index
);
44 void apl_push_apr_table(lua_State
*L
, apr_table_t
*t
)
47 luaL_getmetatable(L
, "Apr.Table");
48 lua_setmetatable(L
, -2);
51 static int lua_table_set(lua_State
*L
)
53 apr_table_t
*t
= check_apr_table(L
, 1);
54 const char *key
= luaL_checkstring(L
, 2);
55 const char *val
= luaL_checkstring(L
, 3);
57 apr_table_set(t
, key
, val
);
61 static int lua_table_get(lua_State
*L
)
63 apr_table_t
*t
= check_apr_table(L
, 1);
64 const char *key
= luaL_checkstring(L
, 2);
65 const char *val
= apr_table_get(t
, key
);
66 lua_pushstring(L
, val
);
70 static const luaL_reg lua_table_methods
[] = {
71 {"set", lua_table_set
},
72 {"get", lua_table_get
},
77 int apr_lua_init(lua_State
*L
, apr_pool_t
*p
)
79 luaL_newmetatable(L
, "Apr.Table");
80 luaL_openlib(L
, "apr_table", lua_table_methods
, 0);
81 lua_pushstring(L
, "__index");
82 lua_pushstring(L
, "get");
86 lua_pushstring(L
, "__newindex");
87 lua_pushstring(L
, "set");