<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40289 >

2008/6/18 Marko Lindqvist:
>
> S2_2 (lua 5.1.3 + patches as 16-Jun-08 + toluaxx)
> Autogames produce error message:
>
> 1:
> lua error:
>        error in error handling

 Attached patch fixes all the errors I were getting from hut code in
script.lua. Error handling, when errors happen, is not completely
fixed.


 - ML

diff -Nurd -X.diff_ignore freeciv/data/default/script.lua 
freeciv/data/default/script.lua
--- freeciv/data/default/script.lua     2007-08-04 18:36:46.000000000 +0300
+++ freeciv/data/default/script.lua     2008-06-22 01:57:44.000000000 +0300
@@ -12,7 +12,7 @@
 -- Get gold from entering a hut.
 function hut_get_gold(unit, gold)
   local owner = unit.owner
- 
+
   notify.event(owner, unit.tile, E.HUT_GOLD, _("You found %d gold."), gold)
   change_gold(owner, gold)
 end
@@ -25,12 +25,12 @@
   if tech then
     notify.event(owner, unit.tile, E.HUT_TECH,
                  _("You found %s in ancient scrolls of wisdom."),
-                 tech:name_translation())
+                 methods_tech_type_name_translation(tech))
     notify.embassies(owner, unit.tile, E.HUT_TECH,
                      _("The %s have acquired %s from ancient scrolls of\
                       wisdom."),
-                     owner.nation:plural_translation(),
-                     tech:name_translation())
+                     methods_nation_type_plural_translation(owner.nation),
+                     methods_tech_type_name_translation(tech))
     return true
   else
     return false
@@ -47,7 +47,7 @@
      
     notify.event(owner, unit.tile, E.HUT_MERC,
                  _("A band of friendly mercenaries joins your cause."))
-    create_unit(owner, unit.tile, type, 0, unit:homecity(), -1)
+    create_unit(owner, unit.tile, type, 0, unit:get_homecity(), -1)
     return true
   else
     return false
@@ -60,11 +60,11 @@
   local settlers = find.unit_type('Settlers')
 
   if unit:is_on_possible_city_tile() then
-    create_city(owner, unit.tile, nil)
+    create_city(owner, unit.tile, "")
     notify.event(owner, unit.tile, E.HUT_CITY,
                  _("You found a friendly city."))
   else
-    create_unit(owner, unit.tile, settlers, 0, unit:homecity(), -1)
+    create_unit(owner, unit.tile, settlers, 0, unit:get_homecity(), -1)
     notify.event(owner, unit.tile, E.HUT_SETTLER,
                  _("Friendly nomads are impressed by you, and join you."))
   end
@@ -76,7 +76,7 @@
   local tile = unit.tile
   local type = unit.utype
   local owner = unit.owner
-  
+
   if unit.tile:city_exists_within_city_radius(true) 
     or type:has_flag('Gameloss') then
     notify.event(owner, unit.tile, E.HUT_BARB_CITY_NEAR,
diff -Nurd -X.diff_ignore freeciv/server/scripting/api_actions.c 
freeciv/server/scripting/api_actions.c
--- freeciv/server/scripting/api_actions.c      2007-08-12 21:14:05.000000000 
+0300
+++ freeciv/server/scripting/api_actions.c      2008-06-22 01:56:15.000000000 
+0300
@@ -51,7 +51,7 @@
 **************************************************************************/
 void api_actions_create_city(Player *pplayer, Tile *ptile, const char *name)
 {
-  if (!name) {
+  if (!name || name[0] == '\0') {
     name = city_name_suggestion(pplayer, ptile);
   }
   create_city(pplayer, ptile, name);
diff -Nurd -X.diff_ignore freeciv/server/scripting/api.pkg 
freeciv/server/scripting/api.pkg
--- freeciv/server/scripting/api.pkg    2008-06-21 18:47:00.000000000 +0300
+++ freeciv/server/scripting/api.pkg    2008-06-22 02:02:49.000000000 +0300
@@ -174,7 +174,7 @@
 end
 
 -- Unit methods.
-function Unit:homecity()
+function Unit:get_homecity()
   return find.city(self.owner, self.homecity)
 end
 
diff -Nurd -X.diff_ignore freeciv/server/scripting/script.c 
freeciv/server/scripting/script.c
--- freeciv/server/scripting/script.c   2008-06-17 15:34:47.000000000 +0300
+++ freeciv/server/scripting/script.c   2008-06-22 01:48:03.000000000 +0300
@@ -60,7 +60,7 @@
     astr_clear(&str);
 
     /* Add error message. */
-    astr_add_line(&str, "\nlua error:");
+    astr_add_line(&str, "lua error:");
     astr_add_line(&str, "\t%s", msg);
 
     if (code) {
@@ -110,6 +110,7 @@
 
     lua_pop(L, 1);
   }
+
   return status;
 }
 
@@ -125,10 +126,10 @@
   lua_rawget(L, LUA_GLOBALSINDEX);  /* Get traceback function */
   lua_insert(L, base);  /* Put it under chunk and args */
   status = lua_pcall(L, narg, nret, base);
-  lua_remove(L, base);  /* Remove traceback function */
   if (status) {
     script_report(state, status, NULL);
   }
+  lua_remove(L, base);  /* Remove traceback function */
   return status;
 }
 
@@ -142,8 +143,12 @@
   status = luaL_loadbuffer(L, str, strlen(str), name);
   if (status) {
     script_report(state, status, str);
+  } else {
+    status = script_call(L, 0, LUA_MULTRET);
+    if (status) {
+      script_report(state, status, str);
+    }
   }
-  status = script_call(L, 0, LUA_MULTRET);
   return status;
 }
 
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to