hedgewars/uScript.pas
branchtransitional_engine
changeset 15929 128ace913837
parent 15604 6a38a30e772a
child 16004 2146cb7be36f
equal deleted inserted replaced
15928:73cdc306888f 15929:128ace913837
   182 begin
   182 begin
   183     LuaError(call + ': ' + error);
   183     LuaError(call + ': ' + error);
   184     LuaError('-- SYNTAX: ' + call + ' ( ' + paramsyntax + ' )');
   184     LuaError('-- SYNTAX: ' + call + ' ( ' + paramsyntax + ' )');
   185 end;
   185 end;
   186 
   186 
   187 procedure LuaParameterCountError(expected, call, paramsyntax: shortstring; wrongcount: LongInt); inline;
   187 procedure LuaParameterCountError(expected, call, paramsyntax: shortstring; wrongcount: LongInt); 
   188 begin
   188 begin
   189     // TODO: i18n?
   189     // TODO: i18n?
   190     LuaCallError('Wrong number of parameters! (is: ' + inttostr(wrongcount) + ', should be: '+ expected + ')', call, paramsyntax);
   190     LuaCallError('Wrong number of parameters! (is: ' + inttostr(wrongcount) + ', should be: '+ expected + ')', call, paramsyntax);
   191 end;
   191 end;
   192 
   192 
   193 // compare with allowed count
   193 // compare with allowed count
   194 function CheckLuaParamCount(L : Plua_State; count: LongInt; call, paramsyntax: shortstring): boolean; inline;
   194 function CheckLuaParamCount(L : Plua_State; count: LongInt; call, paramsyntax: shortstring): boolean; 
   195 var c: LongInt;
   195 var c: LongInt;
   196 begin
   196 begin
   197     c:= lua_gettop(L);
   197     c:= lua_gettop(L);
   198     if c <> count then
   198     if c <> count then
   199         begin
   199         begin
   203 
   203 
   204     CheckLuaParamCount:= true;
   204     CheckLuaParamCount:= true;
   205 end;
   205 end;
   206 
   206 
   207 // check if is either count1 or count2
   207 // check if is either count1 or count2
   208 function CheckAndFetchParamCount(L : Plua_State; count1, count2: LongInt; call, paramsyntax: shortstring; out actual: LongInt): boolean; inline;
   208 function CheckAndFetchParamCount(L : Plua_State; count1, count2: LongInt; call, paramsyntax: shortstring; out actual: LongInt): boolean; 
   209 begin
   209 begin
   210     actual:= lua_gettop(L);
   210     actual:= lua_gettop(L);
   211     if (actual <> count1) and (actual <> count2) then
   211     if (actual <> count1) and (actual <> count2) then
   212         begin
   212         begin
   213         LuaParameterCountError('either ' + inttostr(count1) + ' or ' + inttostr(count2), call, paramsyntax, actual);
   213         LuaParameterCountError('either ' + inttostr(count1) + ' or ' + inttostr(count2), call, paramsyntax, actual);
   216 
   216 
   217     CheckAndFetchParamCount:= true;
   217     CheckAndFetchParamCount:= true;
   218 end;
   218 end;
   219 
   219 
   220 // check if is in range of count1 and count2
   220 // check if is in range of count1 and count2
   221 function CheckAndFetchParamCountRange(L : Plua_State; count1, count2: LongInt; call, paramsyntax: shortstring; out actual: LongInt): boolean; inline;
   221 function CheckAndFetchParamCountRange(L : Plua_State; count1, count2: LongInt; call, paramsyntax: shortstring; out actual: LongInt): boolean; 
   222 begin
   222 begin
   223     actual:= lua_gettop(L);
   223     actual:= lua_gettop(L);
   224     if (actual < count1) or (actual > count2) then
   224     if (actual < count1) or (actual > count2) then
   225         begin
   225         begin
   226         LuaParameterCountError('at least ' + inttostr(count1) + ', but at most ' + inttostr(count2), call, paramsyntax, actual);
   226         LuaParameterCountError('at least ' + inttostr(count1) + ', but at most ' + inttostr(count2), call, paramsyntax, actual);
   229 
   229 
   230     CheckAndFetchParamCountRange:= true;
   230     CheckAndFetchParamCountRange:= true;
   231 end;
   231 end;
   232 
   232 
   233 // check if is same or higher as minCount
   233 // check if is same or higher as minCount
   234 function CheckAndFetchLuaParamMinCount(L : Plua_State; minCount: LongInt; call, paramsyntax: shortstring; out actual: LongInt): boolean; inline;
   234 function CheckAndFetchLuaParamMinCount(L : Plua_State; minCount: LongInt; call, paramsyntax: shortstring; out actual: LongInt): boolean; 
   235 begin
   235 begin
   236     actual:= lua_gettop(L);
   236     actual:= lua_gettop(L);
   237     if (actual < minCount) then
   237     if (actual < minCount) then
   238         begin
   238         begin
   239         LuaParameterCountError(inttostr(minCount) + ' or more', call, paramsyntax, actual);
   239         LuaParameterCountError(inttostr(minCount) + ' or more', call, paramsyntax, actual);
   241         end;
   241         end;
   242 
   242 
   243     CheckAndFetchLuaParamMinCount:= true;
   243     CheckAndFetchLuaParamMinCount:= true;
   244 end;
   244 end;
   245 
   245 
   246 function LuaToGearTypeOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   246 function LuaToGearTypeOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; 
   247 begin
   247 begin
   248     if lua_isnoneornil(L, i) then i:= -1
   248     if lua_isnoneornil(L, i) then i:= -1
   249     else i:= Trunc(lua_tonumber(L, i));
   249     else i:= Trunc(lua_tonumber(L, i));
   250     if (i < ord(Low(TGearType))) or (i > ord(High(TGearType))) then
   250     if (i < ord(Low(TGearType))) or (i > ord(High(TGearType))) then
   251         begin
   251         begin
   254         end
   254         end
   255     else
   255     else
   256         LuaToGearTypeOrd:= i;
   256         LuaToGearTypeOrd:= i;
   257 end;
   257 end;
   258 
   258 
   259 function LuaToVisualGearTypeOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   259 function LuaToVisualGearTypeOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; 
   260 begin
   260 begin
   261     if lua_isnoneornil(L, i) then i:= -1
   261     if lua_isnoneornil(L, i) then i:= -1
   262     else i:= Trunc(lua_tonumber(L, i));
   262     else i:= Trunc(lua_tonumber(L, i));
   263     if (i < ord(Low(TVisualGearType))) or (i > ord(High(TVisualGearType))) then
   263     if (i < ord(Low(TVisualGearType))) or (i > ord(High(TVisualGearType))) then
   264         begin
   264         begin
   267         end
   267         end
   268     else
   268     else
   269         LuaToVisualGearTypeOrd:= i;
   269         LuaToVisualGearTypeOrd:= i;
   270 end;
   270 end;
   271 
   271 
   272 function LuaToAmmoTypeOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   272 function LuaToAmmoTypeOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; 
   273 begin
   273 begin
   274     if lua_isnoneornil(L, i) then i:= -1
   274     if lua_isnoneornil(L, i) then i:= -1
   275     else i:= Trunc(lua_tonumber(L, i));
   275     else i:= Trunc(lua_tonumber(L, i));
   276     if (i < ord(Low(TAmmoType))) or (i > ord(High(TAmmoType))) then
   276     if (i < ord(Low(TAmmoType))) or (i > ord(High(TAmmoType))) then
   277         begin
   277         begin
   280         end
   280         end
   281     else
   281     else
   282         LuaToAmmoTypeOrd:= i;
   282         LuaToAmmoTypeOrd:= i;
   283 end;
   283 end;
   284 
   284 
   285 function LuaToStatInfoTypeOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   285 function LuaToStatInfoTypeOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; 
   286 begin
   286 begin
   287     if lua_isnoneornil(L, i) then i:= -1
   287     if lua_isnoneornil(L, i) then i:= -1
   288     else i:= Trunc(lua_tonumber(L, i));
   288     else i:= Trunc(lua_tonumber(L, i));
   289     if (i < ord(Low(TStatInfoType))) or (i > ord(High(TStatInfoType))) then
   289     if (i < ord(Low(TStatInfoType))) or (i > ord(High(TStatInfoType))) then
   290         begin
   290         begin
   293         end
   293         end
   294     else
   294     else
   295         LuaToStatInfoTypeOrd:= i;
   295         LuaToStatInfoTypeOrd:= i;
   296 end;
   296 end;
   297 
   297 
   298 function LuaToSoundOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   298 function LuaToSoundOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; 
   299 begin
   299 begin
   300     if lua_isnoneornil(L, i) then i:= -1
   300     if lua_isnoneornil(L, i) then i:= -1
   301     else i:= Trunc(lua_tonumber(L, i));
   301     else i:= Trunc(lua_tonumber(L, i));
   302     if (i < ord(Low(TSound))) or (i > ord(High(TSound))) then
   302     if (i < ord(Low(TSound))) or (i > ord(High(TSound))) then
   303         begin
   303         begin
   306         end
   306         end
   307     else
   307     else
   308         LuaToSoundOrd:= i;
   308         LuaToSoundOrd:= i;
   309 end;
   309 end;
   310 
   310 
   311 function LuaToHogEffectOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   311 function LuaToHogEffectOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; 
   312 begin
   312 begin
   313     if lua_isnoneornil(L, i) then i:= -1
   313     if lua_isnoneornil(L, i) then i:= -1
   314     else i:= Trunc(lua_tonumber(L, i));
   314     else i:= Trunc(lua_tonumber(L, i));
   315     if (i < ord(Low(THogEffect))) or (i > ord(High(THogEffect))) then
   315     if (i < ord(Low(THogEffect))) or (i > ord(High(THogEffect))) then
   316         begin
   316         begin
   319         end
   319         end
   320     else
   320     else
   321         LuaToHogEffectOrd:= i;
   321         LuaToHogEffectOrd:= i;
   322 end;
   322 end;
   323 
   323 
   324 function LuaToCapGroupOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   324 function LuaToCapGroupOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; 
   325 begin
   325 begin
   326     if lua_isnoneornil(L, i) then i:= -1
   326     if lua_isnoneornil(L, i) then i:= -1
   327     else i:= Trunc(lua_tonumber(L, i));
   327     else i:= Trunc(lua_tonumber(L, i));
   328     if (i < ord(Low(TCapGroup))) or (i > ord(High(TCapGroup))) then
   328     if (i < ord(Low(TCapGroup))) or (i > ord(High(TCapGroup))) then
   329         begin
   329         begin
   332         end
   332         end
   333     else
   333     else
   334         LuaToCapGroupOrd:= i;
   334         LuaToCapGroupOrd:= i;
   335 end;
   335 end;
   336 
   336 
   337 function LuaToSpriteOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   337 function LuaToSpriteOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; 
   338 begin
   338 begin
   339     if lua_isnoneornil(L, i) then i:= -1
   339     if lua_isnoneornil(L, i) then i:= -1
   340     else i:= Trunc(lua_tonumber(L, i));
   340     else i:= Trunc(lua_tonumber(L, i));
   341     if (i < ord(Low(TSprite))) or (i > ord(High(TSprite))) then
   341     if (i < ord(Low(TSprite))) or (i > ord(High(TSprite))) then
   342         begin
   342         begin
   345         end
   345         end
   346     else
   346     else
   347         LuaToSpriteOrd:= i;
   347         LuaToSpriteOrd:= i;
   348 end;
   348 end;
   349 
   349 
   350 function LuaToMapGenOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   350 function LuaToMapGenOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; 
   351 begin
   351 begin
   352     if lua_isnoneornil(L, i) then i:= -1
   352     if lua_isnoneornil(L, i) then i:= -1
   353     else i:= Trunc(lua_tonumber(L, i));
   353     else i:= Trunc(lua_tonumber(L, i));
   354     if (i < ord(Low(TMapGen))) or (i > ord(High(TMapGen))) then
   354     if (i < ord(Low(TMapGen))) or (i > ord(High(TMapGen))) then
   355         begin
   355         begin