use 0s instead of nils to try to protect script assumptions 0.9.24
authornemo
Tue, 21 Aug 2018 15:26:29 -0400
branch0.9.24
changeset 13683 6c0cf6b9eff8
parent 13682 f60b3998ba56
child 13688 076b7d23fab8
use 0s instead of nils to try to protect script assumptions
hedgewars/uScript.pas
--- a/hedgewars/uScript.pas	Tue Aug 21 15:11:28 2018 -0400
+++ b/hedgewars/uScript.pas	Tue Aug 21 15:26:29 2018 -0400
@@ -862,10 +862,10 @@
                 end;
             end
             else
-                lua_pushnil(L);
+                lua_pushnumber(L,0);
         end
     else
-        lua_pushnil(L); // return value on stack (nil)
+        lua_pushnumber(L,0); // return value on stack (nil)
     lc_addvisualgear:= 1; // 1 return value
 end;
 
@@ -904,7 +904,7 @@
 function lc_getvisualgearvalues(L : Plua_State) : LongInt; Cdecl;
 var vg: PVisualGear;
 begin
-    if not(cOnlyStats) and CheckLuaParamCount(L, 1, 'GetVisualGearValues', 'vgUid') then
+    if not(cOnlyStats) and (Trunc(lua_tonumber(L, 1)) > 0) and CheckLuaParamCount(L, 1, 'GetVisualGearValues', 'vgUid') then
         begin
         vg:= VisualGearByUID(Trunc(lua_tonumber(L, 1)));
         if vg <> nil then
@@ -922,14 +922,14 @@
             end
         else
             begin
-            lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L);
-            lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L);
+            lua_pushnumber(L, 0); lua_pushnumber(L, 0); lua_pushnumber(L, 0); lua_pushnumber(L, 0); lua_pushnumber(L, 0);
+            lua_pushnumber(L, 0); lua_pushnumber(L, 0); lua_pushnumber(L, 0); lua_pushnumber(L, 0); lua_pushnumber(L, 0);
             end
         end
     else
         begin
-        lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L);
-        lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L);
+        lua_pushnumber(L, 0); lua_pushnumber(L, 0); lua_pushnumber(L, 0); lua_pushnumber(L, 0); lua_pushnumber(L, 0);
+        lua_pushnumber(L, 0); lua_pushnumber(L, 0); lua_pushnumber(L, 0); lua_pushnumber(L, 0); lua_pushnumber(L, 0);
         end;
     lc_getvisualgearvalues:= 10
 end;
@@ -938,7 +938,7 @@
 var vg : PVisualGear;
 begin
     lc_setvisualgearvalues:= 0;
-	if cOnlyStats then exit;
+    if cOnlyStats or (Trunc(lua_tonumber(L, 1)) = 0) then exit;
 // Param count can be 1-11 at present
 //    if CheckLuaParamCount(L, 11, 'SetVisualGearValues', 'vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint') then
 //        begin