Add a GetTag method so that SetTag doesn't feel lonely.
authormikade <redgrinner@gmail.com>
Thu, 31 May 2012 15:50:25 +0200
changeset 7156 09262f82e99d
parent 7153 f0d055645ab2
child 7163 7db1e3a7422a
Add a GetTag method so that SetTag doesn't feel lonely.
hedgewars/uScript.pas
--- a/hedgewars/uScript.pas	Thu May 31 00:11:42 2012 +0200
+++ b/hedgewars/uScript.pas	Thu May 31 15:50:25 2012 +0200
@@ -1162,6 +1162,25 @@
     lc_getstate:= 1
 end;
 
+function lc_gettag(L : Plua_State) : LongInt; Cdecl;
+var gear : PGear;
+begin
+    if lua_gettop(L) <> 1 then
+        begin
+        LuaError('Lua: Wrong number of parameters passed to GetX!');
+        lua_pushnil(L); // return value on stack (nil)
+        end
+    else
+        begin
+        gear:= GearByUID(lua_tointeger(L, 1));
+        if gear <> nil then
+            lua_pushinteger(L, gear^.Tag)
+        else
+            lua_pushnil(L);
+        end;
+    lc_gettag:= 1
+end;
+
 function lc_settag(L : Plua_State) : LongInt; Cdecl;
 var gear : PGear;
 begin
@@ -2207,6 +2226,7 @@
 lua_register(luaState, _P'GetFollowGear', @lc_getfollowgear);
 lua_register(luaState, _P'SetState', @lc_setstate);
 lua_register(luaState, _P'GetState', @lc_getstate);
+lua_register(luaState, _P'GetTag', @lc_gettag);
 lua_register(luaState, _P'SetTag', @lc_settag);
 lua_register(luaState, _P'SetTimer', @lc_settimer);
 lua_register(luaState, _P'GetTimer', @lc_gettimer);