From 8bd1765908ac462d520a09d4014947d4ecaf4ded Mon Sep 17 00:00:00 2001 From: jsalmon3 <> Date: Sun, 21 Mar 2004 21:19:46 +0000 Subject: [PATCH] Removed META_LUA --- src/game/savegame.cpp | 3 - src/include/missile.h | 5 - src/include/player.h | 7 - src/include/script.h | 140 --------------- src/include/spells.h | 5 - src/include/stratagus.h | 5 +- src/stratagus/script.cpp | 289 ------------------------------- src/stratagus/script_missile.cpp | 178 ------------------- src/stratagus/script_player.cpp | 213 ----------------------- src/stratagus/script_spell.cpp | 162 ----------------- src/stratagus/stratagus.cpp | 3 - 11 files changed, 1 insertion(+), 1009 deletions(-) diff --git a/src/game/savegame.cpp b/src/game/savegame.cpp index 1cd4b35a6..40b00185a 100644 --- a/src/game/savegame.cpp +++ b/src/game/savegame.cpp @@ -121,9 +121,6 @@ local char* SaveGlobal(lua_State *l, int is_root) || !strcmp(key, "os") || !strcmp(key, "io") || !strcmp(key, "debug") || !strcmp(key, "coroutine") // other string to protected ? -#ifdef META_LUA - || !strcmp(key, "Stratagus") // do not save stratagus table. or should be ? -#endif ))) { lua_pop(l, 1); // pop the value continue; diff --git a/src/include/missile.h b/src/include/missile.h index 76d6deeeb..94806f68a 100644 --- a/src/include/missile.h +++ b/src/include/missile.h @@ -557,11 +557,6 @@ FuncController MissileActionWhirlwind; FuncController MissileActionFlameShield; FuncController MissileActionDeathCoil; -#ifdef META_LUA - /// Initialize Spell scripting. -extern void ScriptMissileTypesInit(void); -#endif - //@} #endif // !__MISSILE_H__ diff --git a/src/include/player.h b/src/include/player.h index cdc0dadb5..2a23d5c08 100644 --- a/src/include/player.h +++ b/src/include/player.h @@ -544,13 +544,6 @@ extern void PlayerCclRegister(void); /// Allowed to select multiple units, maybe not mine #define CanSelectMultipleUnits(player) ((player) == ThisPlayer || PlayersTeamed(ThisPlayer->Player, (player)->Player)) -#ifdef META_LUA - - /// Initialize scripting -extern void ScriptPlayerInit(void); - -#endif - //@} #endif // !__PLAYER_H__ diff --git a/src/include/script.h b/src/include/script.h index 232da3e62..a06795b4d 100644 --- a/src/include/script.h +++ b/src/include/script.h @@ -84,146 +84,6 @@ extern int CclCommand(const char*); /// Execute a ccl command extern void CclFree(void*); /// Save free extern void CleanCclCredits(); /// Free Ccl Credits Memory -#ifdef META_LUA - -/*---------------------------------------------------------------------------- --- Functions and data structures. -----------------------------------------------------------------------------*/ - - /// Script get/set function prototype with string key. The value is on the lua stack. -typedef int ScriptGetSetStrFunction(void* object, const char* key, lua_State* l); - /// Script get/set function prototype with int index. The value is on the lua stack. -typedef int ScriptGetSetIntFunction(void* object, int index, lua_State* l); - /// Script garbage collector function prototype. -typedef int ScriptCollectFunction(void* object); - - /// Structure for a script proxy type. Make one of those for every scriptable struct. -typedef struct { - ScriptGetSetStrFunction* GetStr; /// Get function with strings. - ScriptGetSetStrFunction* SetStr; /// Set function with strings. - ScriptGetSetIntFunction* GetInt; /// Get function with int index. - ScriptGetSetIntFunction* SetInt; /// Set function with int index. - ScriptCollectFunction* Collect; /// Garbage collection function. -} ScriptProxyType; - - /// Structure for a script proxy. Don't mess with this outside of scripting -typedef struct { - void* Object; /// The actual Object - ScriptProxyType* Type; /// Type information -} ScriptProxy; - - /// Userdata Constructor. Push userdata on the stack. -extern void ScriptCreateUserdata(lua_State* l, void* object, ScriptProxyType* type); - /// Init ScriptProxyType with all blockers. -extern void ScriptProxyTypeInitBlock(ScriptProxyType* type); - /// Really dumb set function that always goes into an error, with string key -extern int ScriptGetSetStrBlock(void* object, const char* key, lua_State* l); - /// Really dumb set function that always goes into an error, with int index -extern int ScriptGetSetIntBlock(void* object, int index, lua_State* l); - -/*---------------------------------------------------------------------------- --- Quick macros for meta lua. Use them in well-formed get/set functions. -----------------------------------------------------------------------------*/ - - /// Quick way to fail in a function. You can use _C_ like in DebugLevelx -#define LuaError(l, args) \ - { lua_pushfstring(l, args); lua_error(l); return 0; } - - /// Quick way to check the number of arguments -#define LuaCheckArgCount(l, argcount) \ -{ \ - if (lua_gettop(l) != (argcount)) { \ - LuaError(l, "Wrong number of arguments, expected %d got %d" \ - _C_ (argcount) _C_ lua_gettop(l)); \ - } \ -} - -// -// Pushing 0 as a string to lua is ok. strdup-ing 0 is not. -// -#define META_GET_STRING(keyval, v) \ -{ \ - if (!strcmp(key, keyval)) { \ - if (v) { \ - lua_pushstring(l, strdup(v)); \ - } else { \ - lua_pushstring(l, 0); \ - } \ - return 1; \ - } \ -} - -#define META_SET_STRING(keyval, v) \ -{ \ - if (!strcmp(key, keyval)) { \ - luaL_checktype(l, -1, LUA_TSTRING); \ - v = strdup(lua_tostring(l, -1)); \ - return 0; \ - } \ -} - -#define META_GET_INT(keyval, v) \ -{ \ - if (!strcmp(key, keyval)) { \ - lua_pushnumber(l, v); \ - return 1; \ - } \ -} - -#define META_SET_INT(keyval, v) \ -{ \ - if (!strcmp(key, keyval)) { \ - luaL_checktype(l, -1, LUA_TNUMBER); \ - v = lua_tonumber(l, -1); \ - return 0; \ - } \ -} - -#define META_GET_BOOL(keyval, v) \ -{ \ - if (!strcmp(key, keyval)) { \ - lua_pushboolean(l, v); \ - return 1; \ - } \ -} - -#define META_SET_BOOL(keyval, v) \ -{ \ - if (!strcmp(key, keyval)) { \ - luaL_checktype(l, -1, LUA_TBOOLEAN); \ - v = lua_toboolean(l, -1); \ - return 0; \ - } \ -} - -#define META_GET_FUNC(keyval, v) \ -{ \ - if (!strcmp(key, keyval)) { \ - lua_pushcfunction(l, v); \ - return 1; \ - } \ -} - -/* -#define META_SET_FUNC(keyval, v) \ -{ \ - if (!strcmp(key, keyval)) { \ - luaL_checktype(l, -1, LUA_TBOOLEAN); \ - v = lua_toboolean(l, -1); \ - return 0; \ - } \ -}*/ - -#define META_GET_USERDATA(keyval, obj, type) \ -{ \ - if (!strcmp(key, keyval)) { \ - ScriptCreateUserdata(l, obj, type); \ - return 1; \ - } \ -} - -#endif // META_LUA - //@} #endif // !__CCL_H__ diff --git a/src/include/spells.h b/src/include/spells.h index 39a6078dc..7ef2132aa 100644 --- a/src/include/spells.h +++ b/src/include/spells.h @@ -341,11 +341,6 @@ SpellFunc CastDeathCoil; SpellFunc CastSpawnPortal; SpellFunc CastSpawnMissile; -#ifdef META_LUA - /// Initialize Spell scripting. -extern void ScriptSpellInit(void); -#endif - //@} #endif // !__SPELLS_H__ diff --git a/src/include/stratagus.h b/src/include/stratagus.h index 81340283b..87e2627fb 100644 --- a/src/include/stratagus.h +++ b/src/include/stratagus.h @@ -40,9 +40,6 @@ // New unit cache #define NEW_UNIT_CACHE -// New Lua scripting. -//#define META_LUA - // Dynamic loading. //#define DYNAMIC_LOAD @@ -338,7 +335,7 @@ enum _must_redraw_flags_ { RedrawMenu = 1 << 22, /// Menu RedrawTimer = 1 << 23, /// Timer - // Bits 23-29 are unused. + // Bits 24-29 are unused. RedrawAll = 1 << 30, /// All flag set by RedrawEverything RedrawEverything = -1, /// Must redraw everything diff --git a/src/stratagus/script.cpp b/src/stratagus/script.cpp index d60205c7b..54f653780 100644 --- a/src/stratagus/script.cpp +++ b/src/stratagus/script.cpp @@ -1032,291 +1032,6 @@ global int CclCommand(const char* command) .. Setup ............................................................................*/ -#ifdef META_LUA - -/** -** Generic Get Function for a script proxy. Delegate the call to the object's -** own Get function. -** -** @param l The lua state. -*/ -local int ScriptGet(lua_State* l) -{ - ScriptProxy* sp; - - sp = (ScriptProxy*)lua_touserdata(l, -2); - DebugCheck((!sp) || (!sp->Type)); - if (sp->Type->GetInt && lua_isnumber(l, -1)) { - return sp->Type->GetInt(sp->Object, lua_tonumber(l, -1), l); - } - if (sp->Type->GetStr && lua_isstring(l, -1)) { - return sp->Type->GetStr(sp->Object, lua_tostring(l, -1), l); - } - - LuaError(l, "Only int or string indexing available for userdata, sorry.\n"); -} - -/** -** Generic Set Function for a script proxy. Delegate the call to the object's -** own Set function. -** -** @param l The lua state. -*/ -local int ScriptSet(lua_State* l) -{ - ScriptProxy* sp; - - sp = (ScriptProxy*)lua_touserdata(l, -3); - - if (sp->Type->SetInt && lua_isnumber(l, -2)) { - return sp->Type->SetInt(sp->Object, lua_tonumber(l, -2), l); - } - if (sp->Type->SetStr && lua_isstring(l, -2)) { - return sp->Type->SetStr(sp->Object, lua_tostring(l, -2), l); - } - - LuaError(l, "Only int or string indexing available for userdata, sorry.\n"); -} - -/** -** Generic Collect Function for a script proxy. Delegate the call to the object's -** Collection function. -** -** @param l The lua state. -*/ -local int ScriptCollect(lua_State* l) -{ - ScriptProxy* sp; - char key[20]; - - sp = (ScriptProxy*)lua_touserdata(l, -1); - DebugLevel3Fn("Collecting ScriptProxy at %p for obj at %p.\n" _C_ sp _C_ sp->Object); - // Remove the key from the table. - lua_pushstring(l, "StratagusReferences"); - lua_gettable(l, LUA_REGISTRYINDEX); - sprintf(key, "%p%p", sp->Object, sp->Type); - lua_pushstring(l, key); - lua_pushnil(l); - lua_settable(l, -3); - lua_remove(l, -1); - - // Call custom garbage collector, if any. - if (sp->Type->Collect) { - return sp->Type->Collect(sp); - } - return 0; -} - -/** -** Push a lua proxy on the stack for a C structure. This will not always create new -** userdata, but use an old one for the same structure. The userdata is pushed on -** the lua stack anyway. -** -** @param l The lua state -** @param object The Object to create userdata for. -** @param Type Type info for the object -** -** @note The Object is sent to the get/set functions, otherwise it is not touched. -** @note Internals. All lua proxies are kept inside a weak table inside the registry. -** That table is indexed by the pointer to the object, get and set funcs. When This -** function is called it searches for an already existant userdata, and returns it if found. -** Otherwise it create a new userdata, and sets it's metatable. A garbage collection -** proc is called to remove it from the table. -*/ -global void ScriptCreateUserdata(lua_State* l, void* object, ScriptProxyType* type) -{ - char key[40]; - ScriptProxy* sp; - - // FIXME: FASTER? - sprintf(key, "%p%p", object, type); - lua_pushstring(l, "StratagusReferences"); - lua_gettable(l, LUA_REGISTRYINDEX); - lua_pushstring(l, key); - lua_gettable(l, -2); - - if (lua_isnil(l, -1)) { - lua_remove(l, -1); - // Create userdata. - sp = (ScriptProxy*)lua_newuserdata(l, sizeof(ScriptProxy)); - sp->Object = object; - sp->Type = type; - // Get the standard metatable - lua_pushstring(l, "StratagusStandardMetatable"); - lua_gettable(l, LUA_REGISTRYINDEX); - lua_setmetatable(l, -2); - // Add it to the reference table - lua_pushstring(l, key); - lua_pushvalue(l, -2); - lua_settable(l, -4); - // Remove StratagusReferences reference - lua_remove(l, -2); - DebugLevel3Fn("Creating ScriptProxy at %p for obj at %p.\n" _C_ lua_touserdata(l, -1) _C_ object); - } else { - lua_remove(l, -2); - DebugLevel3Fn("Reusing ScriptProxy at %p for obj at %p.\n" _C_ lua_touserdata(l, -1) _C_ object); - } -} - -/** -** Really dumb set function that always goes into an error, with string key -*/ -global int ScriptGetSetStrBlock(void* object, const char* key, lua_State* l) -{ - LuaError(l, "Access denied"); -} - -/** -** Really dumb set function that always goes into an error, with int index -*/ -global int ScriptGetSetIntBlock(void* object, int index, lua_State* l) -{ - LuaError(l, "Access denied"); -} - -/** -** Initialize a ScriptProxyType with blockers -** -** @param type ScriptProxyType -*/ -global void ScriptProxyTypeInitBlock(ScriptProxyType* type) -{ - type->GetStr = ScriptGetSetStrBlock; - type->SetStr = ScriptGetSetStrBlock; - type->GetInt = ScriptGetSetIntBlock; - type->SetInt = ScriptGetSetIntBlock; - type->Collect = 0; -} - -/** -** Get a value from the Stratagus syncronized random number generator. -*/ -local int ScriptSyncRand(lua_State* l) -{ - LuaCheckArgCount(l, 1); - lua_pushnumber(l, SyncRand() % (int)LuaToNumber(l, -1)); - return 1; -} - -/** -** Get a value from the Stratagus "truly" random number generator. -*/ -local int ScriptMyRand(lua_State* l) -{ - LuaCheckArgCount(l, 1); - lua_pushnumber(l, MyRand() % (int)LuaToNumber(l, -1)); - return 1; -} - -/** -** Get a value from the big Stratagus struct. -*/ -local int ScriptStratagusGetValue(lua_State* l) -{ - const char* key; - - key = LuaToString(l, -1); - DebugCheck(!key); - - META_GET_STRING("LibraryPath", StratagusLibPath); - META_GET_INT("GameCycle", GameCycle); - META_GET_STRING("GameName", GameName); - META_GET_BOOL("GamePaused", GamePaused); - - // Something went wrong. - lua_pushfstring(l, "Unknown field \"%s\". Going DOWN!!!\n", key); - lua_error(l); - return 0; -} - -/** -** Set a value from the big Stratagus struct. -*/ -local int ScriptStratagusSetValue(lua_State* l) -{ - const char* key; - - DebugCheck(lua_gettop(l) != 3); - key = LuaToString(l, -2); - DebugCheck(!key); - - // Here start the fields. - // Sorry, none yet. - - // Something went wrong. - lua_pushfstring(l, "Unknown field \"%s\". Going DOWN!!!\n", key); - lua_error(l); - return 0; - -} - -/** -** Initialize the main Stratagus namespace. -*/ -local void ScriptStratagusInit(void) -{ - lua_pushstring(Lua, "SyncRand"); - lua_pushcfunction(Lua, ScriptSyncRand); - lua_rawset(Lua, -3); - - lua_pushstring(Lua, "MyRand"); - lua_pushcfunction(Lua, ScriptMyRand); - lua_rawset(Lua, -3); -} - -/** -** Initialize metatables and the main stratagus table. -*/ -local void InitScript(void) -{ - lua_pushstring(Lua, "Stratagus"); - - // Generate a weak table in the registry - lua_pushstring(Lua, "StratagusReferences"); - lua_newtable(Lua); - lua_newtable(Lua); - lua_pushstring(Lua, "__mode"); - lua_pushstring(Lua, "v"); - lua_settable(Lua, -3); - lua_setmetatable(Lua, -2); - lua_settable(Lua, LUA_REGISTRYINDEX); - - // Generate a standard metatable - lua_pushstring(Lua, "StratagusStandardMetatable"); - lua_newtable(Lua); - lua_pushstring(Lua, "__index"); - lua_pushcfunction(Lua, ScriptGet); - lua_settable(Lua, -3); - lua_pushstring(Lua, "__newindex"); - lua_pushcfunction(Lua, ScriptSet); - lua_settable(Lua, -3); - lua_pushstring(Lua, "__gc"); - lua_pushcfunction(Lua, ScriptCollect); - lua_settable(Lua, -3); - lua_settable(Lua, LUA_REGISTRYINDEX); - - // This is the main table, and the metatable for Stratagus. - lua_newtable(Lua); - lua_newtable(Lua); - lua_pushstring(Lua, "__index"); - lua_pushcfunction(Lua, ScriptStratagusGetValue); - lua_settable(Lua, -3); - lua_pushstring(Lua, "__newindex"); - lua_pushcfunction(Lua, ScriptStratagusSetValue); - lua_settable(Lua, -3); - lua_setmetatable(Lua, -2); - - // Add all our namespaces and stuff. - ScriptStratagusInit(); - ScriptSpellInit(); - ScriptMissileTypesInit(); - ScriptPlayerInit(); - - lua_settable(Lua, LUA_GLOBALSINDEX); -} - -#endif - /** ** Initialize ccl and load the config file(s). */ @@ -1330,10 +1045,6 @@ global void InitCcl(void) luaopen_debug(Lua); lua_settop(Lua, 0); // discard any results -#ifdef META_LUA - InitScript(); -#endif - lua_register(Lua, "CompileFeature", CclGetCompileFeature); lua_register(Lua, "LibraryPath", CclStratagusLibraryPath); lua_register(Lua, "GameCycle", CclGameCycle); diff --git a/src/stratagus/script_missile.cpp b/src/stratagus/script_missile.cpp index d7c2af05f..c1bde4f32 100644 --- a/src/stratagus/script_missile.cpp +++ b/src/stratagus/script_missile.cpp @@ -425,182 +425,4 @@ global void MissileCclRegister(void) lua_register(Lua, "DefineBurningBuilding", CclDefineBurningBuilding); } -#ifdef META_LUA - - /// Proxy type for MissileType -local ScriptProxyType ScriptProxyMissileType; - /// Proxy type for the SpellType array -local ScriptProxyType ScriptProxyMissileTypes; - -/** -** Create a new missile Type -** -** @param l Lua state -*/ -local int ScriptMissileTypeCreate(lua_State* l) -{ - const char* name; - MissileType* mtype; - - if (lua_gettop(l) != 1) { - LuaError(l, "Incorrect number of arguments"); - } - name = LuaToString(l, 1); - - mtype = MissileTypeByIdent(name); - if (mtype != NULL) { - LuaError(l, "Missile allready exists"); - } else { - mtype = NewMissileTypeSlot(strdup(name)); - - // Defaults. - mtype->NumDirections = 1; - mtype->Flip = 1; - mtype->SplashFactor = 100; - - ScriptCreateUserdata(l, mtype, &ScriptProxyMissileType); - return 1; - } -} - -/** -** Get function for a missile type userdata. -** -** @param missiletype Pointer to the missile type. -** @param key Key string. -*/ -local int ScriptMissileTypeGet(MissileType* mtype, const char* key, lua_State* l) -{ - META_GET_STRING("Ident", mtype->Ident); - META_GET_STRING("File", mtype->File); - - META_GET_INT("Transparency", mtype->Transparency); - META_GET_INT("Width", mtype->Width); - META_GET_INT("Height", mtype->Height); - META_GET_INT("DrawLevel", mtype->DrawLevel); - META_GET_INT("SpriteFrames", mtype->SpriteFrames); - META_GET_INT("NumDirections", mtype->NumDirections); - - META_GET_INT("NumBounces", mtype->NumBounces); - META_GET_INT("Sleep", mtype->Sleep); - META_GET_INT("Speed", mtype->Speed); - META_GET_INT("Range", mtype->Range); - META_GET_INT("SplashFactor", mtype->SplashFactor); - META_GET_BOOL("CanHitOwner", mtype->CanHitOwner); - META_GET_BOOL("FriendlyFire", mtype->FriendlyFire); - - META_GET_STRING("ImpactMissile", mtype->ImpactName); - META_GET_STRING("SmokeMissile", mtype->SmokeName); - - META_GET_STRING("FiredSound", mtype->FiredSound.Name); - META_GET_STRING("ImpactSound", mtype->ImpactSound.Name); - META_GET_STRING("Class", MissileClassNames[mtype->Class]); - - LuaError(l, "Field \"%s\" is innexistent or write-only (yes, we have those).\n" _C_ key); -} - -/** -** Set function for a missile type userdata. -** -** @param missiletype Pointer to the missile type. -** @param key Key string. -*/ -local int ScriptMissileTypeSet(MissileType* mtype, const char* key, lua_State* l) -{ - META_SET_STRING("File", mtype->File); - - META_SET_INT("Transparency", mtype->Transparency); - META_SET_INT("Width", mtype->Width); - META_SET_INT("Height", mtype->Height); - META_SET_INT("DrawLevel", mtype->DrawLevel); - META_SET_INT("SpriteFrames", mtype->SpriteFrames); - META_SET_INT("NumDirections", mtype->NumDirections); - - META_SET_INT("NumBounces", mtype->NumBounces); - META_SET_INT("Sleep", mtype->Sleep); - META_SET_INT("Speed", mtype->Speed); - META_SET_INT("Range", mtype->Range); - META_SET_INT("SplashFactor", mtype->SplashFactor); - META_SET_BOOL("CanHitOwner", mtype->CanHitOwner); - META_SET_BOOL("FriendlyFire", mtype->FriendlyFire); - - META_SET_STRING("ImpactMissile", mtype->ImpactName); - META_SET_STRING("SmokeMissile", mtype->SmokeName); - - META_SET_STRING("FiredSound", mtype->FiredSound.Name); - META_SET_STRING("ImpactSound", mtype->ImpactSound.Name); - - if (!strcmp(key, "Class")) { - const char* value; - int i; - - value = LuaToString(l, -1); - for (i = 0; MissileClassNames[i]; ++i) { - if (!strcmp(value, MissileClassNames[i])) { - mtype->Class = i; - return 0; - } - } - LuaError(l, "Unsupported missile class: %s" _C_ value); - } - - LuaError(l, "Field \"%s\" is innexistent or read-only.\n" _C_ key); -} - -/** -** Get function for the big missile types namespace, with int index -*/ -local int ScriptMissileTypesGetInt(void* object, int index, lua_State* l) -{ - if (index < 0 || index >= NumMissileTypes) { - LuaError(l, "Missile type index out of range"); - } - ScriptCreateUserdata(l, MissileTypes[index], &ScriptProxyMissileType); - return 1; -} - -/** -** Get function for the big missile types namespace, with string key -*/ -local int ScriptMissileTypesGetStr(void* object, const char* key, lua_State* l) -{ - MissileType* mtype; - - META_GET_INT("n", NumMissileTypes); - META_GET_FUNC("Create", ScriptMissileTypeCreate); - if ((mtype = MissileTypeByIdent(key))) { - ScriptCreateUserdata(l, mtype, &ScriptProxyMissileType); - return 1; - } - - LuaError(l, "Missile type \"%s\" doesn't exist.\n" _C_ key); -} - -/** -** Initialize missile scripting. The main table is at -1 -** -** @param l The lua state. -*/ -global void ScriptMissileTypesInit(void) -{ - ScriptProxyMissileType.GetStr = (ScriptGetSetStrFunction *)ScriptMissileTypeGet; - ScriptProxyMissileType.SetStr = (ScriptGetSetStrFunction *)ScriptMissileTypeSet; - ScriptProxyMissileType.GetInt = ScriptGetSetIntBlock; - ScriptProxyMissileType.SetInt = ScriptGetSetIntBlock; - ScriptProxyMissileType.Collect = 0; - - ScriptProxyMissileTypes.GetStr = (ScriptGetSetStrFunction *)ScriptMissileTypesGetStr; - ScriptProxyMissileTypes.SetStr = ScriptGetSetStrBlock; - ScriptProxyMissileTypes.GetInt = (ScriptGetSetIntFunction *)ScriptMissileTypesGetInt; - ScriptProxyMissileTypes.SetInt = ScriptGetSetIntBlock; - ScriptProxyMissileTypes.Collect = 0; - - // Create Stratagus.MissileTypes namespace. - lua_pushstring(Lua, "MissileTypes"); - ScriptCreateUserdata(Lua, 0, &ScriptProxyMissileTypes); - lua_rawset(Lua, -3); -} - -#endif - //@} diff --git a/src/stratagus/script_player.cpp b/src/stratagus/script_player.cpp index d31472665..65c6473ef 100644 --- a/src/stratagus/script_player.cpp +++ b/src/stratagus/script_player.cpp @@ -954,217 +954,4 @@ global void PlayerCclRegister(void) lua_register(Lua, "SetPlayerData", CclSetPlayerData); } -#ifdef META_LUA - - /// Proxy type for the Player array -local ScriptProxyType ScriptProxyPlayerArray; - /// Proxy type for Player -local ScriptProxyType ScriptProxyPlayer; - /// Proxy type for Player->Allied -local ScriptProxyType ScriptProxyPlayerAllied; - /// Proxy type for Player->Enemy -local ScriptProxyType ScriptProxyPlayerEnemy; - /// Proxy type for Player->SharedVision -local ScriptProxyType ScriptProxyPlayerSharedVision; - /// Proxy type for Player->UnitTypesCount -local ScriptProxyType ScriptProxyPlayerUnitTypesCount; - -/** -** Get function for the big Players namespace, with int index -*/ -local int ScriptPlayerArrayGetInt(void* object, int index, lua_State* l) -{ - if (index < 0 || index >= PlayerMax) { - LuaError(l, "Player index out of range"); - } - ScriptCreateUserdata(l, Players + index, &ScriptProxyPlayer); - return 1; -} - -/** -** Get function for a player userdata. -*/ -local int ScriptPlayerGet(Player* player, const char* key, lua_State* l) -{ - META_GET_INT("Slot", player->Player); - META_GET_STRING("Name", player->Name); - - META_GET_INT("TotalNumUnits", player->TotalNumUnits); - META_GET_INT("NumBuildings", player->NumBuildings); - META_GET_INT("UnitLimit", player->UnitLimit); - META_GET_INT("BuildingLimit", player->BuildingLimit); - META_GET_INT("TotalUnitLimit", player->TotalUnitLimit); - META_GET_INT("Supply", player->Supply); - META_GET_INT("Demand", player->Demand); - - META_GET_INT("StartX", player->StartX); - META_GET_INT("StartY", player->StartY); - - META_GET_INT("Score", player->Score); - META_GET_INT("TotalUnits", player->TotalUnits); - META_GET_INT("TotalBuildings", player->TotalBuildings); - META_GET_INT("TotalRazings", player->TotalRazings); - META_GET_INT("TotalKills", player->TotalKills); - - META_GET_USERDATA("Allied", player, &ScriptProxyPlayerAllied); - META_GET_USERDATA("Enemy", player, &ScriptProxyPlayerEnemy); - META_GET_USERDATA("SharedVision", player, &ScriptProxyPlayerSharedVision); - META_GET_USERDATA("UnitTypesCount", player, &ScriptProxyPlayerUnitTypesCount); - META_GET_USERDATA("Research", player, &ScriptProxyPlayer); - - LuaError(l, "Field \"%s\" is innexistent or write-only (yes, we have those).\n" _C_ key); -} - -/** -** Set function for a player userdata. -*/ -local int ScriptPlayerSet(Player* player, const char* key, lua_State* l) -{ - META_SET_STRING("Name", player->Name); - - META_SET_INT("TotalNumUnits", player->TotalNumUnits); - META_SET_INT("NumBuildings", player->NumBuildings); - META_SET_INT("UnitLimit", player->UnitLimit); - META_SET_INT("BuildingLimit", player->BuildingLimit); - META_SET_INT("TotalUnitLimit", player->TotalUnitLimit); - META_SET_INT("Supply", player->Supply); - META_SET_INT("Demand", player->Demand); - - META_SET_INT("StartX", player->StartX); - META_SET_INT("StartY", player->StartY); - - META_SET_INT("Score", player->Score); - META_SET_INT("TotalUnits", player->TotalUnits); - META_SET_INT("TotalBuildings", player->TotalBuildings); - META_SET_INT("TotalRazings", player->TotalRazings); - META_SET_INT("TotalKills", player->TotalKills); - - LuaError(l, "Field \"%s\" is innexistent or read-only.\n" _C_ key); -} - -/** -** Get function for Player->Allied -*/ -local int ScriptPlayerAlliedGet(Player* player, int index, lua_State* l) -{ - lua_pushboolean(l, player->Allied & (1 << index)); - return 1; -} - -/** -** Set function for Player->Allied -*/ -local int ScriptPlayerAlliedSet(Player* player, int index, lua_State* l) -{ - if (LuaToBoolean(l, -1)) { - player->Allied |= (1 << index); - } else { - player->Allied &= ~(1 << index); - } - return 1; -} - -/** -** Get function for Player->Enemy -*/ -local int ScriptPlayerEnemyGet(Player* player, int index, lua_State* l) -{ - lua_pushboolean(l, player->Enemy & (1 << index)); - return 1; -} - -/** -** Set function for Player->Enemy -*/ -local int ScriptPlayerEnemySet(Player* player, int index, lua_State* l) -{ - if (LuaToBoolean(l, -1)) { - player->Enemy |= (1 << index); - } else { - player->Enemy &= ~(1 << index); - } - return 1; -} - -/** -** Get function for Player->SharedVision -*/ -local int ScriptPlayerSharedVisionGet(Player* player, int index, lua_State* l) -{ - lua_pushboolean(l, player->SharedVision & (1 << index)); - return 1; -} - -/** -** Set function for Player->SharedVision -*/ -local int ScriptPlayerSharedVisionSet(Player* player, int index, lua_State* l) -{ - CommandSharedVision(player->Player, LuaToBoolean(l, -1), index); - return 1; -} - -/** -** Get function for Player->UnitTypesCount with string key -*/ -local int ScriptPlayerUnitTypesCountGetStr(Player* player, const char* key, lua_State* l) -{ - UnitType* type; - - if ((type = UnitTypeByIdent(key))) { - lua_pushnumber(l, player->UnitTypesCount[type->Slot]); - return 1; - } - LuaError(l, "Unit \"%s\" not found." _C_ key); -} - -/** -** Get function for Player->UnitTypesCount with int index -*/ -local int ScriptPlayerUnitTypesCountGetInt(Player* player, int index, lua_State* l) -{ - if (index < 0 || index >= NumUnitTypes) { - LuaError(l, "Unittype index out of range."); - } - - lua_pushnumber(l, player->UnitTypesCount[index]); - return 1; -} - -/** -** Initialize player scripting. The main table is at -1 -*/ -global void ScriptPlayerInit(void) -{ - ScriptProxyTypeInitBlock(&ScriptProxyPlayerArray); - ScriptProxyPlayerArray.GetInt = (ScriptGetSetIntFunction *)ScriptPlayerArrayGetInt; - - ScriptProxyTypeInitBlock(&ScriptProxyPlayer); - ScriptProxyPlayer.GetStr = (ScriptGetSetStrFunction *)ScriptPlayerGet; - ScriptProxyPlayer.SetStr = (ScriptGetSetStrFunction *)ScriptPlayerSet; - - ScriptProxyTypeInitBlock(&ScriptProxyPlayerAllied); - ScriptProxyPlayerAllied.GetInt = (ScriptGetSetIntFunction *)ScriptPlayerAlliedGet; - ScriptProxyPlayerAllied.SetInt = (ScriptGetSetIntFunction *)ScriptPlayerAlliedSet; - - ScriptProxyTypeInitBlock(&ScriptProxyPlayerEnemy); - ScriptProxyPlayerEnemy.GetInt = (ScriptGetSetIntFunction *)ScriptPlayerEnemyGet; - ScriptProxyPlayerEnemy.SetInt = (ScriptGetSetIntFunction *)ScriptPlayerEnemySet; - - ScriptProxyTypeInitBlock(&ScriptProxyPlayerSharedVision); - ScriptProxyPlayerSharedVision.GetInt = (ScriptGetSetIntFunction *)ScriptPlayerSharedVisionGet; - ScriptProxyPlayerSharedVision.SetInt = (ScriptGetSetIntFunction *)ScriptPlayerSharedVisionSet; - - ScriptProxyTypeInitBlock(&ScriptProxyPlayerUnitTypesCount); - ScriptProxyPlayerUnitTypesCount.GetStr = (ScriptGetSetStrFunction *)ScriptPlayerUnitTypesCountGetStr; - ScriptProxyPlayerUnitTypesCount.GetInt = (ScriptGetSetIntFunction *)ScriptPlayerUnitTypesCountGetInt; - - // Create Stratagus.Players namespace. - lua_pushstring(Lua, "Players"); - ScriptCreateUserdata(Lua, 0, &ScriptProxyPlayerArray); - lua_rawset(Lua, -3); -} - -#endif - //@} diff --git a/src/stratagus/script_spell.cpp b/src/stratagus/script_spell.cpp index ae2cd41ec..dfb6bdb62 100644 --- a/src/stratagus/script_spell.cpp +++ b/src/stratagus/script_spell.cpp @@ -967,166 +967,4 @@ void SaveSpellAutoCast(CLFile* file, AutoCastInfo* autocast) CLprintf(file, " )\n"); } -#ifdef META_LUA - - /// Proxy type for SpellType -local ScriptProxyType ScriptProxySpell; - /// Proxy type for the SpellType array -local ScriptProxyType ScriptProxySpellTypes; - -// -// Functions directly acessible from lua. Placed in the stratagus namespace. -// - -/** -** Create a new spell -*/ -local int ScriptSpellCreate(lua_State* l) -{ - const char* name; - SpellType* spell; - - if (lua_gettop(l) != 1) { - LuaError(l, "Incorrect number of arguments"); - } - name = LuaToString(l, 1); - - spell = SpellTypeByIdent(name); - if (spell != NULL) { - LuaError(l, "Spell allready exists"); - } else { - SpellTypeTable = realloc(SpellTypeTable, (1 + SpellTypeCount) * sizeof(SpellType*)); - spell = SpellTypeTable[SpellTypeCount++] = malloc(sizeof(SpellType)); - memset(spell, 0, sizeof(SpellType)); - spell->Slot = SpellTypeCount - 1; - spell->Ident = strdup(name); - spell->DependencyId = -1; - ScriptCreateUserdata(l, spell, &ScriptProxySpell); - return 1; - } -} - -/** -** Get function for a spell userdata. -** -** @param spell Pointer to the spell. -** @param key Key string. -*/ -local int ScriptSpellGet(SpellType* spell, const char* key, lua_State* l) -{ - META_GET_STRING("Name", spell->Name); - META_GET_STRING("Ident", spell->Ident); - META_GET_INT("Slot", spell->Slot); - META_GET_INT("ManaCost", spell->ManaCost); - META_GET_INT("Range", spell->Range); - META_GET_BOOL("RepeatCast", spell->RepeatCast); - - // FIXME: macro for enums. - if (!strcmp(key, "Target")) { - switch (spell->Target) { - case TargetSelf: - lua_pushstring(l, "TargetSelf"); - return 1; - case TargetPosition: - lua_pushstring(l, "TargetPosition"); - return 1; - case TargetUnit: - lua_pushstring(l, "TargetUnit"); - return 1; - } - // Somehow Target got a bad value - DebugCheck(1); - } - - LuaError(l, "Field \"%s\" is innexistent or write-only (yes, we have those).\n" _C_ key); -} - -/** -** Set function for a spell userdata. -** -** @param spell Pointer to the spell. -** @param key Key string. -*/ -local int ScriptSpellSet(SpellType* spell, const char* key, lua_State* l) -{ - const char* val; - - META_SET_STRING("Name", spell->Name); - META_SET_INT("ManaCost", spell->ManaCost); - META_SET_INT("Range", spell->Range); - META_SET_BOOL("RepeatCast", spell->RepeatCast); - - // FIXME: macro for enums. - if (!strcmp(key, "Target")) { - val = LuaToString(l, -1); - if (!strcmp(val, "TargetSelf")) { - spell->Target = TargetSelf; - return 0; - } else if (!strcmp(val, "TargetPosition")) { - spell->Target = TargetPosition; - return 0; - } else if (!strcmp(val, "TargetUnit")) { - spell->Target = TargetUnit; - return 0; - } - LuaError(l, "Enum field \"%s\" can't receive value \"%s\"" _C_ key _C_ val); - } - - LuaError(l, "Field \"%s\" is innexistent or read-only.\n" _C_ key); -} - -/** -** Get function for the big spell namespace, with int index -*/ -local int ScriptSpellTypesGetInt(void* object, int index, lua_State* l) -{ - if (index < 0 || index >= SpellTypeCount) { - LuaError(l, "Spell index out of range"); - } - ScriptCreateUserdata(l, SpellTypeTable[index], &ScriptProxySpell); - return 1; -} - -/** -** Get function for the big spell namespace, with string key -*/ -local int ScriptSpellTypesGetStr(void* object, const char* key, lua_State* l) -{ - SpellType* spell; - - META_GET_INT("n", SpellTypeCount); - META_GET_FUNC("Create", ScriptSpellCreate); - if ((spell = SpellTypeByIdent(key))) { - ScriptCreateUserdata(l, spell, &ScriptProxySpell); - return 1; - } - - LuaError(l, "Spell \"%s\" doesn't exist.\n" _C_ key); -} - -/** -** Initialize spell scripting. The main table is at -1 -*/ -global void ScriptSpellInit(void) -{ - ScriptProxySpell.GetStr = (ScriptGetSetStrFunction *)ScriptSpellGet; - ScriptProxySpell.SetStr = (ScriptGetSetStrFunction *)ScriptSpellSet; - ScriptProxySpell.GetInt = ScriptGetSetIntBlock; - ScriptProxySpell.SetInt = ScriptGetSetIntBlock; - ScriptProxySpell.Collect = 0; - - ScriptProxySpellTypes.GetStr = (ScriptGetSetStrFunction *)ScriptSpellTypesGetStr; - ScriptProxySpellTypes.SetStr = ScriptGetSetStrBlock; - ScriptProxySpellTypes.GetInt = (ScriptGetSetIntFunction *)ScriptSpellTypesGetInt; - ScriptProxySpellTypes.SetInt = ScriptGetSetIntBlock; - ScriptProxySpellTypes.Collect = 0; - - // Create Stratagus.Spells namespace. - lua_pushstring(Lua, "Spells"); - ScriptCreateUserdata(Lua, 0, &ScriptProxySpellTypes); - lua_rawset(Lua, -3); -} - -#endif - //@} diff --git a/src/stratagus/stratagus.cpp b/src/stratagus/stratagus.cpp index 86ec52206..e1fe41935 100644 --- a/src/stratagus/stratagus.cpp +++ b/src/stratagus/stratagus.cpp @@ -958,9 +958,6 @@ global int main(int argc, char** argv) #endif #ifdef USE_OPENGL "OPENGL " -#endif -#ifdef META_LUA - "META-LUA" #endif ;