stratagus-cvs
[Top][All Lists]
Advanced

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

[Stratagus-CVS] stratagus/src/game intro.c


From: Jimmy Salmon
Subject: [Stratagus-CVS] stratagus/src/game intro.c
Date: Sat, 15 Nov 2003 15:53:43 -0500

CVSROOT:        /cvsroot/stratagus
Module name:    stratagus
Branch:         
Changes by:     Jimmy Salmon <address@hidden>   03/11/15 15:53:42

Modified files:
        src/game       : intro.c 

Log message:
        Added Credits for lua

Patches:
Index: stratagus/src/game/intro.c
diff -u stratagus/src/game/intro.c:1.103 stratagus/src/game/intro.c:1.104
--- stratagus/src/game/intro.c:1.103    Wed Nov 12 15:43:22 2003
+++ stratagus/src/game/intro.c  Sat Nov 15 15:53:42 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: intro.c,v 1.103 2003/11/12 20:43:22 jsalmon3 Exp $
+//     $Id: intro.c,v 1.104 2003/11/15 20:53:42 jsalmon3 Exp $
 
 //@{
 
@@ -1399,8 +1399,7 @@
        if (gh_eq_p(value, gh_symbol2scm("background"))) {
            GameCredits.Background = gh_scm2newstr(gh_car(list), NULL);
            list = gh_cdr(list);
-       }
-       if (gh_eq_p(value, gh_symbol2scm("name")) ||
+       } else if (gh_eq_p(value, gh_symbol2scm("name")) ||
                gh_eq_p(value, gh_symbol2scm("title")) ||
                gh_eq_p(value, gh_symbol2scm("comment"))) {
            n = get_c_string(gh_car(list));
@@ -1418,6 +1417,60 @@
     return SCM_UNSPECIFIED;
 }
 #elif defined(USE_LUA)
+local int CclCredits(lua_State* l)
+{
+    const char* value;
+    const char* n;
+    int nlen;
+    int len;
+    int args;
+    int j;
+
+    if (GameCredits.Background) {
+       free(GameCredits.Background);
+    }
+    GameCredits.Background = NULL;
+    if (GameCredits.Names) {
+       free(GameCredits.Names);
+       GameCredits.Names = (char*)malloc(1);
+       GameCredits.Names[0] = '\0';
+    }
+    len = 0;
+
+    args = lua_gettop(l);
+    for (j = 0; j < args; ++j) {
+       if (!lua_isstring(l, j + 1)) {
+           lua_pushstring(l, "incorrect argument");
+           lua_error(l);
+       }
+       value = lua_tostring(l, j + 1);
+       ++j;
+       if (!strcmp(value, "background")) {
+           if (!lua_isstring(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           GameCredits.Background = strdup(lua_tostring(l, j + 1));
+       } else if (!strcmp(value, "name") ||
+               !strcmp(value, "title") ||
+               !strcmp(value, "comment")) {
+           if (!lua_isstring(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           n = lua_tostring(l, j + 1);
+           nlen = strlen(n);
+           GameCredits.Names = (char*)realloc(GameCredits.Names, len + nlen + 
2);
+           if (len != 0) {
+               GameCredits.Names[len++] = '\n';
+           }
+           strcpy(GameCredits.Names + len, n);
+           len += nlen;
+       }
+    }
+
+    return 0;
+}
 #endif
 
 /**
@@ -1429,6 +1482,8 @@
     GameCredits.Names = NULL;
 #if defined(USE_GUILE) || defined(USE_SIOD)
     gh_new_procedureN("credits", CclCredits);
+#elif defined(USE_LUA)
+    lua_register(Lua, "Credits", CclCredits);
 #endif
 }
 




reply via email to

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