{ 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);
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));
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));
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;
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;
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;
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;
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;
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;
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)
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
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: