Skip to content
Snippets Groups Projects
Commit d0f2cf65 authored by Marek Vavruša's avatar Marek Vavruša
Browse files

modules+bindings: cleanup

parent 816d629e
No related branches found
No related tags found
No related merge requests found
......@@ -88,8 +88,15 @@ static lookup_table_t wire_flag_names[] = {
{ 0, NULL }
};
#define PKT_UDATA_CHECK(L) \
if (!lua_touserdata(L, 1)) { \
lua_pushstring(L, "bad parameters, expected (pkt[, newvalue])"); \
lua_error(L); \
}
static int pkt_flag(lua_State *L)
{
PKT_UDATA_CHECK(L);
knot_pkt_t *pkt = lua_touserdata(L, 1);
if (lua_gettop(L) > 1 && lua_isnumber(L, 2)) {
int flag_id = lua_tonumber(L, 2);
......@@ -104,6 +111,7 @@ static int pkt_flag(lua_State *L)
static int pkt_opcode(lua_State *L)
{
PKT_UDATA_CHECK(L);
knot_pkt_t *pkt = lua_touserdata(L, 1);
if (lua_gettop(L) > 1 && lua_isnumber(L, 2)) {
knot_wire_set_opcode(pkt->wire, lua_tonumber(L, 2));
......@@ -114,6 +122,7 @@ static int pkt_opcode(lua_State *L)
static int pkt_rcode(lua_State *L)
{
PKT_UDATA_CHECK(L);
knot_pkt_t *pkt = lua_touserdata(L, 1);
if (lua_gettop(L) > 1 && lua_isnumber(L, 2)) {
knot_wire_set_rcode(pkt->wire, lua_tonumber(L, 2));
......@@ -124,6 +133,7 @@ static int pkt_rcode(lua_State *L)
static int pkt_qtype(lua_State *L)
{
PKT_UDATA_CHECK(L);
knot_pkt_t *pkt = lua_touserdata(L, 1);
lua_pushnumber(L, knot_pkt_qtype(pkt));
return 1;
......@@ -131,6 +141,7 @@ static int pkt_qtype(lua_State *L)
static int pkt_qclass(lua_State *L)
{
PKT_UDATA_CHECK(L);
knot_pkt_t *pkt = lua_touserdata(L, 1);
lua_pushnumber(L, knot_pkt_qclass(pkt));
return 1;
......@@ -138,6 +149,7 @@ static int pkt_qclass(lua_State *L)
static int pkt_qname(lua_State *L)
{
PKT_UDATA_CHECK(L);
knot_pkt_t *pkt = lua_touserdata(L, 1);
lua_pushdname(L, knot_pkt_qname(pkt));
return 1;
......@@ -145,6 +157,7 @@ static int pkt_qname(lua_State *L)
static int pkt_question(lua_State *L)
{
PKT_UDATA_CHECK(L);
knot_pkt_t *pkt = lua_touserdata(L, 1);
if (lua_gettop(L) < 4) {
return 0;
......@@ -161,6 +174,7 @@ static int pkt_question(lua_State *L)
static int pkt_begin(lua_State *L)
{
PKT_UDATA_CHECK(L);
knot_pkt_t *pkt = lua_touserdata(L, 1);
knot_pkt_begin(pkt, lua_tointeger(L, 2));
return 0;
......@@ -168,6 +182,7 @@ static int pkt_begin(lua_State *L)
static int pkt_add(lua_State *L)
{
PKT_UDATA_CHECK(L);
knot_pkt_t *pkt = lua_touserdata(L, 1);
if (lua_gettop(L) < 6) {
return 0;
......
......@@ -158,9 +158,12 @@ static int l_ffi_layer_reset(knot_layer_t *ctx)
static int l_ffi_layer_finish(knot_layer_t *ctx)
{
struct kr_request *req = ctx->data;
LAYER_FFI_CALL(ctx, "finish");
lua_pushlightuserdata(L, ctx->data);
return l_ffi_call(L, 2);
lua_pushlightuserdata(L, req);
lua_pushlightuserdata(L, req->answer);
set_metatable(L, META_PKT);
return l_ffi_call(L, 3);
}
static int l_ffi_layer_consume(knot_layer_t *ctx, knot_pkt_t *pkt)
......
......@@ -167,9 +167,8 @@ doesn't provide any layer to capture events. The Lua module can however provide
counter.total = counter.total + 1
return state
end,
finish = function (state, req)
-- catch KNOT_STATE_FAIL = 8, no bindings yet
if state == 8 then
finish = function (state, req, answer)
if state == kres.FAIL then
counter.failed = counter.failed + 1
end
return state
......@@ -256,7 +255,7 @@ See the CGO_ for more information about type conversions and interoperability be
Configuring modules
-------------------
There is a callback ``X_config()`` but it's NOOP for now, as the configuration is not yet implemented.
There is a callback ``X_config()`` that you can implement, see hints module.
.. _mod-properties:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment