From 403dada85a1e75859573a26ed54a72caa693da91 Mon Sep 17 00:00:00 2001
From: James Stevenson <everamzah@users.noreply.github.com>
Date: Fri, 9 Sep 2016 11:47:13 -0400
Subject: [PATCH] Return nil on empty get_area() (#4508)

---
 doc/lua_api.txt                    | 1 +
 src/script/lua_api/l_areastore.cpp | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/doc/lua_api.txt b/doc/lua_api.txt
index da9ebb9f1..c4bc06695 100644
--- a/doc/lua_api.txt
+++ b/doc/lua_api.txt
@@ -2886,6 +2886,7 @@ chosen for you.
 #### Methods
 * `get_area(id, include_borders, include_data)`: returns the area with the id `id`.
   (optional) Boolean values `include_borders` and `include_data` control what's copied.
+  Returns nil if specified area id does not exist.
 * `get_areas_for_pos(pos, include_borders, include_data)`: returns all areas that contain
   the position `pos`. (optional) Boolean values `include_borders` and `include_data` control
   what's copied.
diff --git a/src/script/lua_api/l_areastore.cpp b/src/script/lua_api/l_areastore.cpp
index 20e7875c7..0912e2ab0 100644
--- a/src/script/lua_api/l_areastore.cpp
+++ b/src/script/lua_api/l_areastore.cpp
@@ -111,6 +111,9 @@ int LuaAreaStore::l_get_area(lua_State *L)
 	const Area *res;
 
 	res = ast->getArea(id);
+	if (!res)
+		return 0;
+
 	push_area(L, res, include_borders, include_data);
 
 	return 1;
-- 
GitLab