stratagus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Stratagus-CVS] stratagus/src/unit ccl_unittype.c


From: Jimmy Salmon
Subject: [Stratagus-CVS] stratagus/src/unit ccl_unittype.c
Date: Thu, 20 Nov 2003 00:39:01 -0500

CVSROOT:        /cvsroot/stratagus
Module name:    stratagus
Branch:         
Changes by:     Jimmy Salmon <address@hidden>   03/11/20 00:39:01

Modified files:
        src/unit       : ccl_unittype.c 

Log message:
        More updates to DefineUnitType

Patches:
Index: stratagus/src/unit/ccl_unittype.c
diff -u stratagus/src/unit/ccl_unittype.c:1.114 
stratagus/src/unit/ccl_unittype.c:1.115
--- stratagus/src/unit/ccl_unittype.c:1.114     Wed Nov 19 19:56:13 2003
+++ stratagus/src/unit/ccl_unittype.c   Thu Nov 20 00:39:00 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: ccl_unittype.c,v 1.114 2003/11/20 00:56:13 jsalmon3 Exp $
+//     $Id: ccl_unittype.c,v 1.115 2003/11/20 05:39:00 jsalmon3 Exp $
 
 //@{
 
@@ -200,8 +200,8 @@
                i = 0;
                if (strcmp(str, "default")) {
                    for (; i < NumTilesets; ++i) {
-                       if (!strcmp(str,Tilesets[i]->Ident) ||
-                               !strcmp(str,Tilesets[i]->Class)) {
+                       if (!strcmp(str, Tilesets[i]->Ident) ||
+                               !strcmp(str, Tilesets[i]->Class)) {
                            break;
                        }
                    }
@@ -723,6 +723,8 @@
     int redefine;
     int args;
     int j;
+    int subargs;
+    int k;
 
     args = lua_gettop(l);
     j = 0;
@@ -793,38 +795,47 @@
            }
            type->SameSprite = strdup(lua_tostring(l, j + 1));
        } else if (!strcmp(value, "files")) {
-#if 0
-           sublist = gh_car(list);
-           list = gh_cdr(list);
-           while (!gh_null_p(sublist)) {
-               char* str;
-
-               value = gh_car(sublist);
-               sublist = gh_cdr(sublist);
+           if (!lua_istable(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           subargs = luaL_getn(l, j + 1);
+           for (k = 0; k < subargs; ++k) {
+               lua_rawgeti(l, j + 1, k + 1);
+               if (!lua_isstring(l, -1)) {
+                   lua_pushstring(l, "incorrect argument");
+                   lua_error(l);
+               }
+               value = lua_tostring(l, -1);
+               lua_pop(l, 1);
+               ++k;
 
                // FIXME: use a general get tileset function here!
-               str = gh_scm2newstr(value, NULL);
                i = 0;
-               if (strcmp(str, "default")) {
+               if (strcmp(value, "default")) {
                    for (; i < NumTilesets; ++i) {
-                       if (!strcmp(str,Tilesets[i]->Ident) ||
-                               !strcmp(str,Tilesets[i]->Class)) {
+                       if (!strcmp(value, Tilesets[i]->Ident) ||
+                               !strcmp(value, Tilesets[i]->Class)) {
                            break;
                        }
                    }
                    if (i == NumTilesets) {
                       // FIXME: this leaves half initialized unit-type
-                      errl("Unsupported tileset tag", value);
+                      lua_pushfstring(l, "Unsupported tileset tag", value);
+                      lua_error(l);
                    }
                }
-               free(str);
                if (redefine) {
                    free(type->File[i]);
                }
-               type->File[i] = gh_scm2newstr(gh_car(sublist), NULL);
-               sublist = gh_cdr(sublist);
+               lua_rawgeti(l, j + 1, k + 1);
+               if (!lua_isstring(l, -1)) {
+                   lua_pushstring(l, "incorrect argument");
+                   lua_error(l);
+               }
+               type->File[i] = strdup(lua_tostring(l, -1));
+               lua_pop(l, 1);
            }
-#endif
        } else if (!strcmp(value, "shadow")) {
 #if 0
            sublist = gh_car(list);
@@ -852,12 +863,24 @@
            }
 #endif
        } else if (!strcmp(value, "size")) {
-#if 0
-           sublist = gh_car(list);
-           list = gh_cdr(list);
-           type->Width = gh_scm2int(gh_car(sublist));
-           type->Height = gh_scm2int(gh_cadr(sublist));
-#endif
+           if (!lua_istable(l, j + 1) || luaL_getn(l, j + 1) != 2) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           lua_rawgeti(l, j + 1, 1);
+           if (!lua_isnumber(l, -1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->Width = lua_tonumber(l, -1);
+           lua_pop(l, 1);
+           lua_rawgeti(l, j + 1, 2);
+           if (!lua_isnumber(l, -1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->Height = lua_tonumber(l, -1);
+           lua_pop(l, 1);
        } else if (!strcmp(value, "animations")) {
            if (!lua_isstring(l, j + 1)) {
                lua_pushstring(l, "incorrect argument");
@@ -953,12 +976,24 @@
            }
            type->_MaxMana = lua_tonumber(l, j + 1);
        } else if (!strcmp(value, "tile-size")) {
-#if 0
-           sublist = gh_car(list);
-           list = gh_cdr(list);
-           type->TileWidth = gh_scm2int(gh_car(sublist));
-           type->TileHeight = gh_scm2int(gh_cadr(sublist));
-#endif
+           if (!lua_istable(l, j + 1) || luaL_getn(l, j + 1) != 2) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           lua_rawgeti(l, j + 1, 1);
+           if (!lua_isnumber(l, -1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->TileWidth = lua_tonumber(l, -1);
+           lua_pop(l, 1);
+           lua_rawgeti(l, j + 1, 2);
+           if (!lua_isnumber(l, -1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->TileHeight = lua_tonumber(l, -1);
+           lua_pop(l, 1);
        } else if (!strcmp(value, "must-build-on-top")) {
            if (!lua_isstring(l, j + 1)) {
                lua_pushstring(l, "incorrect argument");
@@ -989,12 +1024,24 @@
 #endif
 #endif
        } else if (!strcmp(value, "box-size")) {
-#if 0
-           sublist = gh_car(list);
-           list = gh_cdr(list);
-           type->BoxWidth = gh_scm2int(gh_car(sublist));
-           type->BoxHeight = gh_scm2int(gh_cadr(sublist));
-#endif
+           if (!lua_istable(l, j + 1) || luaL_getn(l, j + 1) != 2) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           lua_rawgeti(l, j + 1, 1);
+           if (!lua_isnumber(l, -1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->BoxWidth = lua_tonumber(l, -1);
+           lua_pop(l, 1);
+           lua_rawgeti(l, j + 1, 2);
+           if (!lua_isnumber(l, -1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->BoxHeight = lua_tonumber(l, -1);
+           lua_pop(l, 1);
        } else if (!strcmp(value, "num-directions")) {
            if (!lua_isnumber(l, j + 1)) {
                lua_pushstring(l, "incorrect argument");




reply via email to

[Prev in Thread] Current Thread [Next in Thread]