]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/bindings: add lua_pushpointer()
authorVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 15 Apr 2019 11:50:51 +0000 (13:50 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Thu, 18 Apr 2019 07:44:12 +0000 (09:44 +0200)
Originally it's from another branch.

daemon/bindings/impl.h

index af54ddc0bae573261b5b92f7489ecd2eea9d12fa..c4d06c84b4a246fcf2dca72d8972ea25fa9ea375 100644 (file)
@@ -102,3 +102,15 @@ static inline int execute_callback(lua_State *L, int argc)
        return ret;
 }
 
+/** Push a pointer as heavy/full userdata.
+ *
+ * It's useful as a replacement of lua_pushlightuserdata(),
+ * but note that it behaves differently in lua (converts to pointer-to-pointer).
+ */
+static inline void lua_pushpointer(lua_State *L, void *p)
+{
+       void *addr = lua_newuserdata(L, sizeof(void *));
+       assert(addr);
+       memcpy(addr, &p, sizeof(void *));
+}
+