____ _ __
/ __ )____ _____ | | / /___ ___________
/ __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
/ /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
/_____/\____/____/ |__/|__/\__,_/_/ /____/
A futuristic real-time strategy game.
This file is part of Bos Wars.
(C) Copyright 2001-2007 by the Bos Wars and Stratagus Project.
Distributed under the "GNU General Public License"
#include <string>
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
Go to the source code of this file.
Classes | |
| struct | _lua_user_data_ |
Defines | |
| #define | LuaError(l, args) |
| #define | LuaCheckArgs(l, args) |
Typedefs | |
| typedef struct _lua_user_data_ | LuaUserData |
Enumerations | |
| enum | { LuaUnitType = 100, LuaSoundType } |
Functions | |
| int | LuaLoadFile (const std::string &file) |
| int | LuaCall (int narg, int clear, bool exitOnError=true) |
| const char * | LuaToString (lua_State *l, int narg) |
| int | LuaToNumber (lua_State *l, int narg) |
| bool | LuaToBoolean (lua_State *l, int narg) |
| void | CclGarbageCollect (int fast) |
| Perform garbage collection. | |
| void | InitCcl (void) |
| Initialise ccl. | |
| void | LoadCcl (void) |
| Load ccl config file. | |
| void | SaveCcl (CFile *file) |
| Save CCL module. | |
| void | SavePreferences (void) |
| Save user preferences. | |
| char * | SaveGlobal (lua_State *l, bool is_root) |
| For saving lua state. | |
| int | CclCommand (const std::string &command, bool exitOnError=true) |
| Execute a ccl command. | |
Variables | |
| lua_State * | Lua |
| Structure to work with lua files. | |
| std::string | CclStartFile |
| CCL start file. | |
| int | CclInConfigFile |
| True while config file parsing. | |
Definition in file script.h.
| #define LuaCheckArgs | ( | l, | |||
| args | ) |
Value:
do { \ if (lua_gettop(l) != args) { \ LuaError(l, "incorrect argument"); \ } \ } while (0)
Definition at line 78 of file script.h.
Referenced by CclAddMessage(), CclAddTrigger(), CclAiAttackWithForce(), CclAiCheckForce(), CclAiDebug(), CclAiDump(), CclAiForce(), CclAiForceRole(), CclAiGetSleepCycles(), CclAiNeed(), CclAiPlayer(), CclAiSet(), CclAiSleep(), CclAiWait(), CclAiWaitForce(), CclCenterMap(), CclChangeUnitsOwner(), CclCreateUnit(), CclDefineAi(), CclDefineAnimations(), CclDefineButton(), CclDefineButtonStyle(), CclDefineConstruction(), CclDefineCursor(), CclDefineMapSetup(), CclDefineMissileType(), CclDefinePlayerColorIndex(), CclDefinePlayerColors(), CclDefineUnitType(), CclFilteredListDirectory(), CclGetCompileFeature(), CclGetCurrentLuaPath(), CclGetFogOfWar(), CclGetGodMode(), CclGetLocalPlayerName(), CclGetNumUnitsAt(), CclGetSpeedBuild(), CclGetSpeedTrain(), CclGetUnits(), CclGetUnitVariable(), CclGetVideoFullScreen(), CclGetVideoResolution(), CclGroup(), CclIfNearUnit(), CclIfRescuedNearUnit(), CclKillUnit(), CclKillUnitAt(), CclLoad(), CclLoadBuffer(), CclLog(), CclMakeSound(), CclMakeSoundGroup(), CclMapSound(), CclMoveUnit(), CclNewPlayerColors(), CclNoRandomPlacementMultiplayer(), CclOrderUnit(), CclPlaySound(), CclPresentMap(), CclReplayLog(), CclRevealMap(), CclRightButtonAttacks(), CclRightButtonMoves(), CclSavedGameInfo(), CclSavePreferences(), CclSelection(), CclSetAllPlayersBuildingLimit(), CclSetAllPlayersTotalUnitLimit(), CclSetAllPlayersUnitLimit(), CclSetBuildingCapture(), CclSetDiplomacy(), CclSetFogOfWar(), CclSetFogOfWarGraphics(), CclSetGameCursor(), CclSetGlobalSoundRange(), CclSetGodMode(), CclSetGroupId(), CclSetGroupKeys(), CclSetLocalPlayerName(), CclSetMaxSelectable(), CclSetMinimapTerrain(), CclSetMouseScrollSpeedControl(), CclSetMouseScrollSpeedDefault(), CclSetResourcesHeld(), CclSetSharedVision(), CclSetSoundRange(), CclSetSpeedBuild(), CclSetSpeeds(), CclSetSpeedTrain(), CclSetUnitVariable(), CclSetVideoFullScreen(), and CclSetVideoResolution().
| #define LuaError | ( | l, | |||
| args | ) |
Value:
do { \ fprintf(stdout, "%s:%d: ", __FILE__, __LINE__); \ fprintf(stdout, args); \ fprintf(stdout, "\n"); \ lua_pushfstring(l, args); lua_error(l); \ } while (0)
Definition at line 70 of file script.h.
Referenced by Ccl2Condition(), CclAddTrigger(), CclAiAttackWithForce(), CclAiForce(), CclAiForceRole(), CclAiWaitForce(), CclChangeUnitsOwner(), CclCreateUnit(), CclDefineAi(), CclDefineAiHelper(), CclDefineAiPlayer(), CclDefineAnimations(), CclDefineBurningBuilding(), CclDefineButton(), CclDefineButtonStyle(), CclDefineConstruction(), CclDefineCursor(), CclDefineDecorations(), CclDefineGameSounds(), CclDefineMissileType(), CclDefinePlayerColors(), CclDefinePlayerTypes(), CclDefineSpell(), CclDefineSprites(), CclDefineUnitType(), CclDefineViewports(), CclFilteredListDirectory(), CclGetNumUnitsAt(), CclGetResourceByName(), CclGetSound(), CclGetUnitType(), CclGetUnitVariable(), CclIfNearUnit(), CclIfRescuedNearUnit(), CclKillUnitAt(), CclLog(), CclMakeSound(), CclMissile(), CclOrderUnit(), CclParseBuilt(), CclParseHarvest(), CclParseMove(), CclParseOrder(), CclParseTrain(), CclPlayer(), CclReplayLog(), CclSavedGameInfo(), CclSelection(), CclSetClickMissile(), CclSetDamageMissile(), CclSetResourcesHeld(), CclSetTitleScreens(), CclSetUnitVariable(), CclSlotUsage(), CclSpellAction(), CclSpellAutocast(), CclSpellCondition(), CclSpellMissileLocation(), CclStratagusMap(), CclUnit(), DefineVariableField(), FindLabel(), HandleCommandKey(), LuaCallback::LuaCallback(), ParseAnimation(), ParseAnimationFrame(), ParseBuildingRules(), ParseButtonStyleProperties(), and TriggerGetPlayer().
| typedef struct _lua_user_data_ LuaUserData |
| int CclCommand | ( | const std::string & | command, | |
| bool | exitOnError | |||
| ) |
Execute a ccl command.
Send command to ccl.
| command | Zero terminated command string. | |
| exitOnError | Exit if an error occurs. |
Definition at line 716 of file script.cpp.
References Lua, LuaCall(), and report().
Referenced by DoNextReplay(), GameMainLoop(), and InputKey().
| void CclGarbageCollect | ( | int | fast | ) |
Perform garbage collection.
Perform CCL garbage collection
| fast | set this flag to disable slow GC (during game) |
Definition at line 437 of file script.cpp.
References _C_, DebugPrint, and Lua.
Referenced by CEditor::Init(), LoadCcl(), and LoadGame().
| void InitCcl | ( | void | ) |
Initialise ccl.
Initialize ccl and load the config file(s).
Definition at line 767 of file script.cpp.
References AiCclRegister(), CclDefineDefaultResourceNames(), CclGetCompileFeature(), CclGetCurrentLuaPath(), CclGetGodMode(), CclGetLocalPlayerName(), CclGetSpeedBuild(), CclGetSpeedTrain(), CclListDirectory(), CclListDirsInDirectory(), CclListFilesInDirectory(), CclLoad(), CclLoadBuffer(), CclNoRandomPlacementMultiplayer(), CclSavedGameInfo(), CclSavePreferences(), CclSetGodMode(), CclSetLocalPlayerName(), CclSetSpeedBuild(), CclSetSpeeds(), CclSetSpeedTrain(), CclStratagusLibraryPath(), ConstructionCclRegister(), DecorationCclRegister(), GroupCclRegister(), IconCclRegister(), InitLua(), Lua, MapCclRegister(), MissileCclRegister(), PlayerCclRegister(), ReplayCclRegister(), SelectionCclRegister(), SoundCclRegister(), SpellCclRegister(), TriggerCclRegister(), UnitCclRegister(), UnitTypeCclRegister(), UpgradesCclRegister(), and UserInterfaceCclRegister().
Referenced by main().
| void LoadCcl | ( | void | ) |
Load ccl config file.
Load stratagus config file.
Definition at line 1067 of file script.cpp.
References CclGarbageCollect(), CclInConfigFile, CclStartFile, ExitFatal(), LibraryFileName(), LuaLoadFile(), and ShowLoadProgress().
Referenced by EditorMainLoop(), and main().
| int LuaCall | ( | int | narg, | |
| int | clear, | |||
| bool | exitOnError | |||
| ) |
Call a lua function
| narg | Number of arguments | |
| clear | Clear the return value(s) | |
| exitOnError | Exit the program when an error occurs |
Definition at line 174 of file script.cpp.
References laction(), Lua, luatraceback(), and report().
Referenced by AiExecuteScript(), CallHandler(), CclCommand(), CheckMusicFinished(), HandleCheats(), HandleCommandKey(), InitTriggers(), LuaLoadFile(), TriggerExecuteAction(), and TriggersEachCycle().
| int LuaLoadFile | ( | const std::string & | file | ) |
Load a file and execute it
| file | File to load and execute |
Definition at line 248 of file script.cpp.
References CurrentLuaFile, Lua, LuaCall(), LuaLoadBuffer(), and report().
Referenced by CclLoad(), CclSavedGameInfo(), CreateGame(), CEditor::Init(), LoadCcl(), LoadGame(), LoadReplay(), LoadStratagusMap(), LoadStratagusMapInfo(), and MenuLoop().
| bool LuaToBoolean | ( | lua_State * | l, | |
| int | narg | |||
| ) |
Convert lua boolean to bool. It also checks type and exits in case of error.
| l | Lua state. | |
| narg | Argument number. |
Definition at line 426 of file script.cpp.
Referenced by CclAiDebug(), CclDefineAiPlayer(), CclDefineDecorations(), CclDefineMissileType(), CclDefineUnitType(), CclReplayLog(), CclSetActiveTriggers(), CclSetBuildingCapture(), CclSetFogOfWar(), CclSetGodMode(), CclSetMinimapTerrain(), CclSetSharedVision(), CclSetTitleScreens(), CclSetVideoFullScreen(), CclSpellAction(), CclSpellCondition(), DefineVariableField(), HandleCheats(), HandleCommandKey(), and ParseBuildingRules().
| int LuaToNumber | ( | lua_State * | l, | |
| int | narg | |||
| ) |
Convert lua number in C number. It checks also type and exit in case of error.
| l | Lua state. | |
| narg | Argument number. |
Definition at line 411 of file script.cpp.
Referenced by CclAiAttackWithForce(), CclAiCheckForce(), CclAiDebugPlayer(), CclAiForce(), CclAiForceRole(), CclAiSet(), CclAiSleep(), CclAiWaitForce(), CclCenterMap(), CclChangeUnitsOwner(), CclCreateUnit(), CclDefineAiPlayer(), CclDefineBurningBuilding(), CclDefineButton(), CclDefineButtonStyle(), CclDefineConstruction(), CclDefineCursor(), CclDefineDecorations(), CclDefineMissileType(), CclDefinePlayerColorIndex(), CclDefinePlayerColors(), CclDefineSpell(), CclDefineSprites(), CclDefineUnitAllow(), CclDefineUnitType(), CclDefineViewports(), CclGetNumUnitsAt(), CclGetUnit(), CclGroup(), CclIfNearUnit(), CclIfRescuedNearUnit(), CclKillUnitAt(), CclLog(), CclMissile(), CclMoveUnit(), CclOrderUnit(), CclParseBuilt(), CclParseHarvest(), CclParseMove(), CclParseOrder(), CclParseTrain(), CclPlayer(), CclPresentMap(), CclReplayLog(), CclSavedGameInfo(), CclSelection(), CclSetAllPlayersBuildingLimit(), CclSetAllPlayersTotalUnitLimit(), CclSetAllPlayersUnitLimit(), CclSetDiplomacy(), CclSetGlobalSoundRange(), CclSetGroupId(), CclSetMaxSelectable(), CclSetMouseScrollSpeedControl(), CclSetMouseScrollSpeedDefault(), CclSetResourcesHeld(), CclSetSharedVision(), CclSetSoundRange(), CclSetSpeedBuild(), CclSetSpeeds(), CclSetSpeedTrain(), CclSetTitleScreens(), CclSetUnitVariable(), CclSetVideoResolution(), CclSlotUsage(), CclSpellAction(), CclSpellAutocast(), CclSpellCondition(), CclSpellMissileLocation(), CclStratagusMap(), CclUnit(), DefineVariableField(), ParseBuildingRules(), ParseButtonStyleProperties(), and TriggerGetPlayer().
| const char* LuaToString | ( | lua_State * | l, | |
| int | narg | |||
| ) |
Convert lua string in char*. It checks also type and exit in case of error.
| l | Lua state. | |
| narg | Argument number. |
Definition at line 396 of file script.cpp.
Referenced by CclAddMessage(), CclAiDebugPlayer(), CclAiForceRole(), CclDefineAi(), CclDefineAiHelper(), CclDefineAiPlayer(), CclDefineAllow(), CclDefineAnimations(), CclDefineBurningBuilding(), CclDefineButton(), CclDefineButtonStyle(), CclDefineConstruction(), CclDefineCursor(), CclDefineDecorations(), CclDefineDefaultResourceNames(), CclDefineGameSounds(), CclDefineMapSetup(), CclDefineMissileType(), CclDefinePlayerColors(), CclDefinePlayerTypes(), CclDefineSpell(), CclDefineSprites(), CclDefineUnitAllow(), CclDefineUnitType(), CclDefineVariables(), CclDefineViewports(), CclGetCompileFeature(), CclGetResourceByName(), CclGetUnitType(), CclGetUnitVariable(), CclGroup(), CclIfNearUnit(), CclIfRescuedNearUnit(), CclLoad(), CclLoadBuffer(), CclLog(), CclMakeSound(), CclMakeSoundGroup(), CclMapSound(), CclMissile(), CclOrderUnit(), CclParseBuilt(), CclParseHarvest(), CclParseMove(), CclParseOrder(), CclParseTrain(), CclPlayer(), CclPresentMap(), CclReplayLog(), CclSavedGameInfo(), CclSelection(), CclSetDiplomacy(), CclSetFogOfWarGraphics(), CclSetGameCursor(), CclSetGroupKeys(), CclSetLocalPlayerName(), CclSetTitleScreens(), CclSetUnitVariable(), CclSlotUsage(), CclSoundForName(), CclSpellAction(), CclSpellAutocast(), CclSpellCondition(), CclSpellMissileLocation(), CclStratagusMap(), CclUnit(), DefineVariableField(), ParseAnimation(), ParseBuildingRules(), ParseButtonStyleProperties(), LuaListModel::setList(), TriggerGetPlayer(), and TriggerGetUnitType().
| void SaveCcl | ( | CFile * | file | ) |
Save CCL module.
Save CCL Module.
| file | Save file. |
Definition at line 1092 of file script.cpp.
References GodMode, CFile::printf(), SpeedBuild, and SpeedTrain.
Referenced by SaveGame().
| char* SaveGlobal | ( | lua_State * | l, | |
| bool | is_root | |||
| ) |
For saving lua state.
For saving lua state (table, number, string, bool, not function).
| l | lua_State to save. | |
| is_root | true for the main call, 0 for recursif call. |
Definition at line 860 of file script.cpp.
References Assert, LuaEscape(), new_strdup(), SaveGlobal(), and strdcat3().
Referenced by SaveGame(), SaveGlobal(), and SavePreferences().
| void SavePreferences | ( | void | ) |
Save user preferences.
Save user preferences
Definition at line 1041 of file script.cpp.
References Lua, SaveGlobal(), and UserDirectory.
Referenced by CclSavePreferences(), and CommandKey().
| int CclInConfigFile |
True while config file parsing.
Definition at line 72 of file script.cpp.
Referenced by CclRevealMap(), CclSetFogOfWar(), CclSetVideoFullScreen(), CclSetVideoResolution(), and LoadCcl().
| std::string CclStartFile |
| lua_State* Lua |
Structure to work with lua files.
Definition at line 68 of file script.cpp.
Referenced by AiCclRegister(), AiExecuteScript(), CallHandler(), CclCommand(), CclGarbageCollect(), CheckMusicFinished(), CleanTriggers(), ConstructionCclRegister(), DecorationCclRegister(), Exit(), GroupCclRegister(), HandleCheats(), HandleCommandKey(), InitCcl(), InitLua(), InitTriggers(), laction(), LuaCall(), LuaLoadFile(), MapCclRegister(), MissileCclRegister(), PlayerCclRegister(), ReplayCclRegister(), report(), SaveGame(), SavePreferences(), SaveTriggers(), SelectionCclRegister(), SoundCclRegister(), SpellCclRegister(), TriggerCclRegister(), TriggerExecuteAction(), TriggerRemoveTrigger(), TriggersEachCycle(), UnitCclRegister(), UnitTypeCclRegister(), UpgradesCclRegister(), and UserInterfaceCclRegister().
1.5.6