diff --git a/mongoose.c b/mongoose.c
index 8b14ca655aaf19440e2b53b33e9f96c21b7137a9..20ffb1091d02d7e13e77ac3adb778e4a1feca00f 100644
--- a/mongoose.c
+++ b/mongoose.c
@@ -2627,7 +2627,8 @@ static int lua_write(lua_State *L) {
   int i, num_args;
   const char *str;
   size_t size;
-  struct mg_connection *conn = lua_touserdata(L, lua_upvalueindex(1));
+  struct mg_connection *conn = (struct mg_connection *)
+    lua_touserdata(L, lua_upvalueindex(1));
 
   num_args = lua_gettop(L);
   for (i = 1; i <= num_args; i++) {