stratagus-cvs
[Top][All Lists]
Advanced

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

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


From: Jimmy Salmon
Subject: [Stratagus-CVS] stratagus/src/unit ccl_unit.c ccl_unittype.c de...
Date: Wed, 12 Nov 2003 15:31:18 -0500

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

Modified files:
        src/unit       : ccl_unit.c ccl_unittype.c depend.c unittype.c 
                         upgrade.c 

Log message:
        Started lua support

Patches:
Index: stratagus/src/unit/ccl_unit.c
diff -u stratagus/src/unit/ccl_unit.c:1.73 stratagus/src/unit/ccl_unit.c:1.74
--- stratagus/src/unit/ccl_unit.c:1.73  Mon Nov 10 22:06:54 2003
+++ stratagus/src/unit/ccl_unit.c       Wed Nov 12 15:31:16 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: ccl_unit.c,v 1.73 2003/11/11 03:06:54 n0body Exp $
+//     $Id: ccl_unit.c,v 1.74 2003/11/12 20:31:16 jsalmon3 Exp $
 
 //@{
 
@@ -57,17 +57,21 @@
 ----------------------------------------------------------------------------*/
 
     /// Get unit-type.
+#if defined(USE_GUILE) || defined(USE_SIOD)
 extern UnitType* CclGetUnitType(SCM ptr);
     /// Get resource by name
 extern unsigned CclGetResourceByName(SCM ptr);
+#elif defined(USE_LUA)
+#endif
 
 /**
-**  Set xp damage
+**     Set xp damage
 **
-**  @param flag Flag enabling or disabling it.
+**     @param flag Flag enabling or disabling it.
 **
-**  @return     The old state of the xp damage
+**     @return     The old state of the xp damage
 */
+#if defined(USE_GUILE) || defined(USE_SIOD)
 local SCM CclSetXpDamage(SCM flag)
 {
     int old;
@@ -77,6 +81,22 @@
 
     return gh_bool2scm(old);
 }
+#elif defined(USE_LUA)
+local int CclSetXpDamage(lua_State* l)
+{
+    int old;
+
+    if (lua_gettop(l) != 1 || !lua_isboolean(l, 1)) {
+       lua_pushstring(l, "incorrect argument");
+       lua_error(l);
+    }
+    old = XpDamage;
+    XpDamage = lua_toboolean(l, 1);
+
+    lua_pushboolean(l, old);
+    return 1;
+}
+#endif
 
 /**
 **     Set training queue
@@ -85,6 +105,7 @@
 **
 **     @return         The old state of the training queue
 */
+#if defined(USE_GUILE) || defined(USE_SIOD)
 local SCM CclSetTrainingQueue(SCM flag)
 {
     int old;
@@ -94,6 +115,22 @@
 
     return gh_bool2scm(old);
 }
+#elif defined(USE_LUA)
+local int CclSetTrainingQueue(lua_State* l)
+{
+    int old;
+
+    if (lua_gettop(l) != 1 || !lua_isboolean(l, 1)) {
+       lua_pushstring(l, "incorrect argument");
+       lua_error(l);
+    }
+    old = EnableTrainingQueue;
+    EnableTrainingQueue = lua_toboolean(l, 1);
+
+    lua_pushboolean(l, old);
+    return 1;
+}
+#endif
 
 /**
 **     Set capture buildings
@@ -102,6 +139,7 @@
 **
 **     @return         The old state of the flag
 */
+#if defined(USE_GUILE) || defined(USE_SIOD)
 local SCM CclSetBuildingCapture(SCM flag)
 {
     int old;
@@ -111,6 +149,22 @@
 
     return gh_bool2scm(old);
 }
+#elif defined(USE_LUA)
+local int CclSetBuildingCapture(lua_State* l)
+{
+    int old;
+
+    if (lua_gettop(l) != 1 || !lua_isboolean(l, 1)) {
+       lua_pushstring(l, "incorrect argument");
+       lua_error(l);
+    }
+    old = EnableBuildingCapture;
+    EnableBuildingCapture = lua_toboolean(l, 1);
+
+    lua_pushboolean(l, old);
+    return 1;
+}
+#endif
 
 /**
 **     Set reveal attacker
@@ -119,6 +173,7 @@
 **
 **     @return         The old state of the flag
 */
+#if defined(USE_GUILE) || defined(USE_SIOD)
 local SCM CclSetRevealAttacker(SCM flag)
 {
     int old;
@@ -128,6 +183,22 @@
 
     return gh_bool2scm(old);
 }
+#elif defined(USE_LUA)
+local int CclSetRevealAttacker(lua_State* l)
+{
+    int old;
+
+    if (lua_gettop(l) != 1 || !lua_isboolean(l, 1)) {
+       lua_pushstring(l, "incorrect argument");
+       lua_error(l);
+    }
+    old = RevealAttacker;
+    RevealAttacker = lua_toboolean(l, 1);
+
+    lua_pushboolean(l, old);
+    return 1;
+}
+#endif
 
 /**
 **     Get a unit pointer
@@ -136,6 +207,7 @@
 **
 **     @return         The unit pointer
 */
+#if defined(USE_GUILE) || defined(USE_SIOD)
 local Unit* CclGetUnit(SCM value)
 {
     return UnitSlots[gh_scm2int(value)];
@@ -1175,6 +1247,8 @@
     return SCM_UNSPECIFIED;
 #undef SLOT_LEN
 }
+#elif defined(USE_LUA)
+#endif
 
 // FIXME: write the missing access functions
 
@@ -1183,6 +1257,7 @@
 */
 global void UnitCclRegister(void)
 {
+#if defined(USE_GUILE) || defined(USE_SIOD)
     gh_new_procedure1_0("set-xp-damage!", CclSetXpDamage);
     gh_new_procedure1_0("set-training-queue!", CclSetTrainingQueue);
     gh_new_procedure1_0("set-building-capture!", CclSetBuildingCapture);
@@ -1202,6 +1277,27 @@
     gh_new_procedure2_0("set-unit-unholy-armor!", CclSetUnitUnholyArmor);
 
     gh_new_procedure1_0 ("slot-usage", CclSlotUsage);
+#elif defined(USE_LUA)
+    lua_register(Lua, "SetXPDamage", CclSetXpDamage);
+    lua_register(Lua, "SetTrainingQueue", CclSetTrainingQueue);
+    lua_register(Lua, "SetBuildingCapture", CclSetBuildingCapture);
+    lua_register(Lua, "SetRevealAttacker", CclSetRevealAttacker);
+
+//    lua_register(Lua, "Unit", CclUnit);
+
+//    lua_register(Lua, "MakeUnit", CclMakeUnit);
+//    lua_register(Lua, "PlaceUnit", CclPlaceUnit);
+//    lua_register(Lua, "CreateUnit", CclCreateUnit);
+//    lua_register(Lua, "OrderUnit", CclOrderUnit);
+//    lua_register(Lua, "KillUnit", CclKillUnit);
+//    lua_register(Lua, "KillUnitAt", CclKillUnitAt);
+
+    // unit member access functions
+//    lua_register(Lua, "GetUnitUnholyArmor", CclGetUnitUnholyArmor);
+//    lua_register(Lua, "SetUnitUnholyArmor", CclSetUnitUnholyArmor);
+
+//    lua_register(Lua, "SlotUsage", CclSlotUsage);
+#endif
 }
 
 //@}
Index: stratagus/src/unit/ccl_unittype.c
diff -u stratagus/src/unit/ccl_unittype.c:1.111 
stratagus/src/unit/ccl_unittype.c:1.112
--- stratagus/src/unit/ccl_unittype.c:1.111     Mon Nov 10 14:25:34 2003
+++ stratagus/src/unit/ccl_unittype.c   Wed Nov 12 15:31:17 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: ccl_unittype.c,v 1.111 2003/11/10 19:25:34 pludov Exp $
+//     $Id: ccl_unittype.c,v 1.112 2003/11/12 20:31:17 jsalmon3 Exp $
 
 //@{
 
@@ -60,7 +60,10 @@
 
 global _AnimationsHash AnimationsHash; /// Animations hash table
 
+#if defined(USE_GUILE) || defined(USE_SIOD)
 local ccl_smob_type_t SiodUnitTypeTag;         /// siod unit-type object
+#elif defined(USE_LUA)
+#endif
 
 global char **BoolFlagName = NULL;     /// Name of user defined flag
 global int NumberBoolFlag = 0;         /// Number of defined flags.
@@ -75,6 +78,7 @@
 **     @param value    SCM thingie
 **     @return         the resource id
 */
+#if defined(USE_GUILE) || defined(USE_SIOD)
 global unsigned CclGetResourceByName(SCM value)
 {
     int i;
@@ -964,12 +968,15 @@
 
     return property;
 }
+#elif defined(USE_LUA)
+#endif
 
 /**
 **     Define tileset mapping from original number to internal symbol
 **
 **     @param list     List of all names.
 */
+#if defined(USE_GUILE) || defined(USE_SIOD)
 local SCM CclDefineUnitTypeWcNames(SCM list)
 {
     int i;
@@ -995,6 +1002,42 @@
 
     return SCM_UNSPECIFIED;
 }
+#elif defined(USE_LUA)
+local int CclDefineUnitTypeWcNames(lua_State* l)
+{
+    int i;
+    int j;
+    char** cp;
+
+    if ((cp = UnitTypeWcNames)) {      // Free all old names
+       while (*cp) {
+           free(*cp++);
+       }
+       free(UnitTypeWcNames);
+    }
+
+    //
+    // Get new table.
+    //
+    i = lua_gettop(l);
+    UnitTypeWcNames = cp = malloc((i + 1) * sizeof(char*));
+    if (!cp) {
+       fprintf(stderr, "out of memory.\n");
+       ExitFatal(-1);
+    }
+
+    for (j = 0; j < i; ++j) {
+       if (!lua_isstring(l, j + 1)) {
+           lua_pushstring(l, "incorrect argument");
+           lua_error(l);
+       }
+       *cp++ = strdup(lua_tostring(l, j + 1));
+    }
+    *cp = NULL;
+
+    return 0;
+}
+#endif
 
 // ----------------------------------------------------------------------------
 
@@ -1003,6 +1046,7 @@
 **
 **     @param list     Animations list.
 */
+#if defined(USE_GUILE) || defined(USE_SIOD)
 local SCM CclDefineAnimations(SCM list)
 {
     char* str;
@@ -1131,6 +1175,8 @@
     }
     return SCM_UNSPECIFIED;
 }
+#elif defined(USE_LUA)
+#endif
 
 // ----------------------------------------------------------------------------
 
@@ -1139,6 +1185,7 @@
 */
 global void UnitTypeCclRegister(void)
 {
+#if defined(USE_GUILE) || defined(USE_SIOD)
     gh_new_procedureN("define-unit-type", CclDefineUnitType);
     gh_new_procedureN("define-unit-stats", CclDefineUnitStats);
     gh_new_procedureN("define-bool-flags", CclDefineBoolFlags);
@@ -1164,6 +1211,30 @@
     gh_new_procedureN("define-unittype-wc-names", CclDefineUnitTypeWcNames);
 
     gh_new_procedureN("define-animations", CclDefineAnimations);
+#elif defined(USE_LUA)
+//    lua_register(Lua, "DefineUnitType", CclDefineUnitType);
+//    lua_register(Lua, "DefineUnitStats", CclDefineUnitStats);
+//    lua_register(Lua, "DefineBoolFlags", CclDefineBoolFlags);
+
+//    SiodUnitTypeTag = CclMakeSmobType("UnitType");
+
+//    lua_register(Lua, "UnitType", CclUnitType);
+//    lua_register(Lua, "UnitTypeArray", CclUnitTypeArray);
+    // unit type structure access
+//    lua_register(Lua, "GetUnitTypeIdent", CclGetUnitTypeIdent);
+//    lua_register(Lua, "GetUnitTypeName", CclGetUnitTypeName);
+//    lua_register(Lua, "SetUnitTypeName", CclSetUnitTypeName);
+
+    // FIXME: write the missing access functions
+
+//    lua_register(Lua, "GetUnitTypeProperty", CclGetUnitTypeProperty);
+//    lua_register(Lua, "SetUnitTypeProperty", CclSetUnitTypeProperty);
+
+    lua_register(Lua, "DefineUnitTypeWcNames", CclDefineUnitTypeWcNames);
+
+//    lua_register(Lua, "DefineAnimations", CclDefineAnimations);
+
+#endif
 }
 
 //@}
Index: stratagus/src/unit/depend.c
diff -u stratagus/src/unit/depend.c:1.31 stratagus/src/unit/depend.c:1.32
--- stratagus/src/unit/depend.c:1.31    Tue Oct 28 13:59:01 2003
+++ stratagus/src/unit/depend.c Wed Nov 12 15:31:17 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: depend.c,v 1.31 2003/10/28 18:59:01 jsalmon3 Exp $
+//     $Id: depend.c,v 1.32 2003/11/12 20:31:17 jsalmon3 Exp $
 
 //@{
 
@@ -286,7 +286,7 @@
     const DependRule* temp;
 
     CLprintf(file,"\n;;; -----------------------------------------\n");
-    CLprintf(file,";;; MODULE: dependencies $Id: depend.c,v 1.31 2003/10/28 
18:59:01 jsalmon3 Exp $\n\n");
+    CLprintf(file,";;; MODULE: dependencies $Id: depend.c,v 1.32 2003/11/12 
20:31:17 jsalmon3 Exp $\n\n");
 
     // Save all dependencies
 
@@ -385,6 +385,7 @@
 **
 **     @param list     List of the dependency.
 */
+#if defined(USE_GUILE) || defined(USE_SIOD)
 local SCM CclDefineDependency(SCM list)
 {
     char* target;
@@ -462,15 +463,19 @@
 
     return SCM_UNSPECIFIED;
 }
+#elif defined(USE_LUA)
+#endif
 
 /**
 **     Register CCL features for dependencies.
 */
 global void DependenciesCclRegister(void)
 {
+#if defined(USE_GUILE) || defined(USE_SIOD)
     gh_new_procedureN("define-dependency", CclDefineDependency);
     gh_new_procedure1_0("get-dependency", CclGetDependency);
     gh_new_procedure1_0("check-dependency", CclCheckDependency);
+#endif
 }
 
 //@}
Index: stratagus/src/unit/unittype.c
diff -u stratagus/src/unit/unittype.c:1.125 stratagus/src/unit/unittype.c:1.126
--- stratagus/src/unit/unittype.c:1.125 Mon Nov 10 14:25:35 2003
+++ stratagus/src/unit/unittype.c       Wed Nov 12 15:31:17 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: unittype.c,v 1.125 2003/11/10 19:25:35 pludov Exp $
+//     $Id: unittype.c,v 1.126 2003/11/12 20:31:17 jsalmon3 Exp $
 
 //@{
 
@@ -1191,7 +1191,7 @@
     char** sp;
 
     CLprintf(file, "\n;;; -----------------------------------------\n");
-    CLprintf(file, ";;; MODULE: unittypes $Id: unittype.c,v 1.125 2003/11/10 
19:25:35 pludov Exp $\n\n");
+    CLprintf(file, ";;; MODULE: unittypes $Id: unittype.c,v 1.126 2003/11/12 
20:31:17 jsalmon3 Exp $\n\n");
 
     // Original number to internal unit-type name.
 
@@ -1525,9 +1525,12 @@
        free(type->BoolFlag);
        free(type->CanTargetFlag);
 
+#if defined(USE_GUILE) || defined(USE_SIOD)
        if ((SCM)type->Property != SCM_UNSPECIFIED) {
            CclGcUnprotect((SCM*)&type->Property);
        }
+#elif defined(USE_LUA)
+#endif
 
        if (type->SameSprite) {
            free(type->SameSprite);
Index: stratagus/src/unit/upgrade.c
diff -u stratagus/src/unit/upgrade.c:1.63 stratagus/src/unit/upgrade.c:1.64
--- stratagus/src/unit/upgrade.c:1.63   Tue Oct 28 17:23:23 2003
+++ stratagus/src/unit/upgrade.c        Wed Nov 12 15:31:17 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: upgrade.c,v 1.63 2003/10/28 22:23:23 jsalmon3 Exp $
+//     $Id: upgrade.c,v 1.64 2003/11/12 20:31:17 jsalmon3 Exp $
 
 //@{
 
@@ -544,7 +544,7 @@
     int p;
 
     CLprintf(file, "\n;;; -----------------------------------------\n");
-    CLprintf(file, ";;; MODULE: upgrades $Id: upgrade.c,v 1.63 2003/10/28 
22:23:23 jsalmon3 Exp $\n\n");
+    CLprintf(file, ";;; MODULE: upgrades $Id: upgrade.c,v 1.64 2003/11/12 
20:31:17 jsalmon3 Exp $\n\n");
 
     /* remove?
     //
@@ -707,6 +707,7 @@
 **
 **     @param list     List of modifiers.
 */
+#if defined(USE_GUILE) || defined(USE_SIOD)
 local SCM CclDefineModifier(SCM list)
 {
     SCM temp;
@@ -927,12 +928,15 @@
 
     return SCM_UNSPECIFIED;
 }
+#elif defined(USE_LUA)
+#endif
 
 /**
 **     Define upgrade mapping from original number to internal symbol
 **
 **     @param list     List of all names.
 */
+#if defined(USE_GUILE) || defined(USE_SIOD)
 local SCM CclDefineUpgradeWcNames(SCM list)
 {
     int i;
@@ -958,17 +962,61 @@
 
     return SCM_UNSPECIFIED;
 }
+#elif defined(USE_LUA)
+local int CclDefineUpgradeWcNames(lua_State* l)
+{
+    int i;
+    int j;
+    char** cp;
+
+    if ((cp = UpgradeWcNames)) {       // Free all old names
+       while (*cp) {
+           free(*cp++);
+       }
+       free(UpgradeWcNames);
+    }
+
+    //
+    // Get new table.
+    //
+    i = lua_gettop(l);
+    UpgradeWcNames = cp = malloc((i + 1) * sizeof(char*));
+    if (!cp) {
+       fprintf(stderr, "out of memory.\n");
+       ExitFatal(-1);
+    }
+
+    for (j = 0; j < i; ++j) {
+       if (!lua_isstring(l, j + 1)) {
+           lua_pushstring(l, "incorrect argument");
+           lua_error(l);
+       }
+       *cp++ = strdup(lua_tostring(l, j + 1));
+    }
+    *cp = NULL;
+
+    return 0;
+}
+#endif
 
 /**
 **     Register CCL features for upgrades.
 */
 global void UpgradesCclRegister(void)
 {
+#if defined(USE_GUILE) || defined(USE_SIOD)
     gh_new_procedureN("define-modifier", CclDefineModifier);
     gh_new_procedureN("define-upgrade", CclDefineUpgrade);
     gh_new_procedureN("define-allow", CclDefineAllow);
 
     gh_new_procedureN("define-upgrade-wc-names", CclDefineUpgradeWcNames);
+#elif defined(USE_LUA)
+//    lua_register(Lua, "DefineModifier", CclDefineModifier);
+//    lua_register(Lua, "DefineUpgrade", CclDefineUpgrade);
+//    lua_register(Lua, "DefineAllow", CclDefineAllow);
+
+    lua_register(Lua, "DefineUpgradeWcNames", CclDefineUpgradeWcNames);
+#endif
 }
 
 




reply via email to

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