diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp
index 13ba72056a6a53ba25b9dcb94d465c3442ac5077..6e2a0a3140f6d67a3c686e2fd6185ca5cdcf9314 100644
--- a/src/scriptapi.cpp
+++ b/src/scriptapi.cpp
@@ -4428,8 +4428,8 @@ static int l_log(lua_State *L)
 	}
 	else
 	{
-		std::string levelname = lua_tostring(L, 1);
-		text = lua_tostring(L, 2);
+		std::string levelname = luaL_checkstring(L, 1);
+		text = luaL_checkstring(L, 2);
 		if(levelname == "error")
 			level = LMT_ERROR;
 		else if(levelname == "action")