_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

Classes
script.h File Reference
#include <string>
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>

Go to the source code of this file.

Classes

struct  LuaUserData
 
struct  BinOp
 for Bin operand a ?? b More...
 
struct  NumberDesc
 
struct  UnitDesc
 
struct  StringDesc
 

script.h - The clone configuration language headerfile.

#define LuaError(l, args)
 
#define LuaCheckArgs(l, args)
 
enum  { LuaUnitType = 100, LuaSoundType }
 
enum  ENumber {
  ENumber_Lua, ENumber_Dir, ENumber_Add, ENumber_Sub,
  ENumber_Mul, ENumber_Div, ENumber_Min, ENumber_Max,
  ENumber_Rand, ENumber_Gt, ENumber_GtEq, ENumber_Lt,
  ENumber_LtEq, ENumber_Eq, ENumber_NEq, ENumber_VideoTextLength,
  ENumber_StringFind, ENumber_UnitStat, ENumber_TypeStat, ENumber_NumIf,
  ENumber_PlayerData
}
 All possible value for a number. More...
 
enum  EUnit { EUnit_Ref }
 All possible value for a unit. More...
 
enum  EString {
  EString_Lua, EString_Dir, EString_Concat, EString_String,
  EString_InverseVideo, EString_If, EString_UnitName, EString_SubString,
  EString_Line, EString_PlayerName
}
 All possible value for a string. More...
 
enum  ES_GameInfo { ES_GameInfo_Objectives }
 All possible value for a game info string. More...
 
enum  EnumVariable {
  VariableValue = 0, VariableMax, VariableIncrease, VariableDiff,
  VariablePercent, VariableName
}
 
enum  EnumUnit {
  UnitRefItSelf = 0, UnitRefInside, UnitRefContainer, UnitRefWorker,
  UnitRefGoal
}
 
lua_State * Lua
 
int CclInConfigFile
 Structure to work with lua files. More...
 
NumberDescDamage
 True while config file parsing. More...
 
int LuaLoadFile (const std::string &file, const std::string &strArg="", bool exitOnError=true)
 
int LuaCall (int narg, int clear, bool exitOnError=true)
 
int LuaCall (lua_State *L, int narg, int nresults, int base, bool exitOnError=true)
 
size_t lua_rawlen (lua_State *l, int index)
 
const char * LuaToString (lua_State *l, int narg)
 True while config file parsing. More...
 
int LuaToNumber (lua_State *l, int narg)
 
float LuaToFloat (lua_State *l, int narg)
 
unsigned int LuaToUnsignedNumber (lua_State *l, int narg)
 
bool LuaToBoolean (lua_State *l, int narg)
 
const char * LuaToString (lua_State *l, int index, int subIndex)
 
int LuaToNumber (lua_State *l, int index, int subIndex)
 
unsigned int LuaToUnsignedNumber (lua_State *l, int index, int subIndex)
 
bool LuaToBoolean (lua_State *l, int index, int subIndex)
 
void LuaGarbageCollect ()
 
void InitLua ()
 Perform garbage collection. More...
 
void LoadCcl (const std::string &filename, const std::string &luaArgStr="")
 Initialise Lua. More...
 
void SavePreferences ()
 Load ccl config file. More...
 
int CclCommand (const std::string &command, bool exitOnError=true)
 Save user preferences. More...
 
void ScriptRegister ()
 
std::string SaveGlobal (lua_State *l)
 
CUnitCclGetUnitFromRef (lua_State *l)
 For saving lua state. More...
 
template<typename T >
static void CclGetPos (lua_State *l, T *x, T *y, const int offset=-1)
 
EnumVariable Str2EnumVariable (lua_State *l, const char *s)
 Damage calculation for missile. More...
 
NumberDescCclParseNumberDesc (lua_State *l)
 
UnitDescCclParseUnitDesc (lua_State *l)
 Parse a number description. More...
 
CUnitType ** CclParseTypeDesc (lua_State *l)
 Parse a unit description. More...
 
StringDescCclParseStringDesc (lua_State *l)
 Parse a unit type description. More...
 
int EvalNumber (const NumberDesc *numberdesc)
 Parse a string description. More...
 
CUnitEvalUnit (const UnitDesc *unitdesc)
 Evaluate the number. More...
 
std::string EvalString (const StringDesc *s)
 Evaluate the unit. More...
 
void FreeNumberDesc (NumberDesc *number)
 Evaluate the string. More...
 
void FreeUnitDesc (UnitDesc *unitdesc)
 Free number description content. (no pointer itself). More...
 
void FreeStringDesc (StringDesc *s)
 Free unit description content. (no pointer itself). More...
 

Macro Definition Documentation

◆ LuaCheckArgs

#define LuaCheckArgs (   l,
  args 
)
Value:
do { \
if (lua_gettop(l) != args) { \
LuaError(l, "incorrect argument"); \
} \
} while (0)

◆ LuaError

#define LuaError (   l,
  args 
)
Value:
do { \
PrintFunction(); \
fprintf(stdout, args); \
fprintf(stdout, "\n"); \
lua_pushfstring(l, args); lua_error(l); \
} while (0)

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
LuaUnitType 
LuaSoundType 

◆ ENumber

enum ENumber

All possible value for a number.

Enumerator
ENumber_Lua 
ENumber_Dir 

a lua function.

ENumber_Add 

directly a number.

ENumber_Sub 

a + b.

ENumber_Mul 

a - b.

ENumber_Div 

a * b.

ENumber_Min 

a / b.

ENumber_Max 

Min(a, b).

ENumber_Rand 

Max(a, b).

ENumber_Gt 

Rand(a) : number in [0..a-1].

ENumber_GtEq 

a > b.

ENumber_Lt 

a >= b.

ENumber_LtEq 

a < b.

ENumber_Eq 

a <= b.

ENumber_NEq 

a == b.

ENumber_VideoTextLength 

a <> b.

ENumber_StringFind 

VideoTextLength(font, string).

ENumber_UnitStat 

strchr(string, char) - s.

ENumber_TypeStat 

Property of Unit.

ENumber_NumIf 

Property of UnitType.

ENumber_PlayerData 

If cond then Number1 else Number2.

Numeric Player Data

◆ EnumUnit

enum EnumUnit

Enumeration of unit

Enumerator
UnitRefItSelf 
UnitRefInside 

unit.

UnitRefContainer 

unit->Inside.

UnitRefWorker 

Unit->Container.

UnitRefGoal 

unit->Data.Built.Worker

unit->Goal

◆ EnumVariable

Enumeration to know which variable to be selected.

Enumerator
VariableValue 
VariableMax 

Value of the variable.

VariableIncrease 

Max of the variable.

VariableDiff 

Increase value of the variable.

VariablePercent 

(Max - Value)

VariableName 

(100 * Value / Max)

Name of the variable.

◆ ES_GameInfo

All possible value for a game info string.

Enumerator
ES_GameInfo_Objectives 

All Objectives of the game.

◆ EString

enum EString

All possible value for a string.

Enumerator
EString_Lua 
EString_Dir 

a lua function.

EString_Concat 

directly a string.

EString_String 

a + b [+ c ...].

EString_InverseVideo 

Convert number in string.

EString_If 

Inverse video for the string ("a" -> "~<a~>").

EString_UnitName 

If cond then String1 else String2.

EString_SubString 

UnitType Name.

EString_Line 

SubString.

EString_PlayerName 

line n of the string.

player name.

◆ EUnit

enum EUnit

All possible value for a unit.

Enumerator
EUnit_Ref 

Unit direct reference.

Function Documentation

◆ CclCommand()

int CclCommand ( const std::string &  command,
bool  exitOnError 
)

Save user preferences.

Send command to ccl.

Parameters
commandZero terminated command string.

◆ CclGetPos()

template<typename T >
static void CclGetPos ( lua_State *  l,
T *  x,
T *  y,
const int  offset = -1 
)
static

Get a position from lua state

Parameters
lLua state.
xpointer to output x position.
ypointer to output y position.

◆ CclGetUnitFromRef()

CUnit* CclGetUnitFromRef ( lua_State *  l)

For saving lua state.

Get a unit pointer from ref string

Parameters
lLua state.
Returns
The unit pointer

◆ CclParseNumberDesc()

NumberDesc* CclParseNumberDesc ( lua_State *  l)

Return number.

Parameters
llua state.
Returns
number.

◆ CclParseStringDesc()

StringDesc* CclParseStringDesc ( lua_State *  l)

Parse a unit type description.

Return String description.

Parameters
llua state.
Returns
String description.

◆ CclParseTypeDesc()

CUnitType** CclParseTypeDesc ( lua_State *  l)

Parse a unit description.

Return unit type referernce definition.

Parameters
llua state.
Returns
unit type referernce definition.

◆ CclParseUnitDesc()

UnitDesc* CclParseUnitDesc ( lua_State *  l)

Parse a number description.

Return unit referernce definition.

Parameters
llua state.
Returns
unit referernce definition.

◆ EvalNumber()

int EvalNumber ( const NumberDesc number)

Parse a string description.

compute the number expression

Parameters
numberstruct with definition of the calculation.
Returns
the result number.
Todo:
Manage better the error (div/0, unit==NULL, ...).

◆ EvalString()

std::string EvalString ( const StringDesc s)

Evaluate the unit.

compute the string expression

Parameters
sstruct with definition of the calculation.
Returns
the result string.
Todo:
Manage better the error.

◆ EvalUnit()

CUnit* EvalUnit ( const UnitDesc unitdesc)

Evaluate the number.

compute the Unit expression

Parameters
unitdescstruct with definition of the calculation.
Returns
the result unit.

◆ FreeNumberDesc()

void FreeNumberDesc ( NumberDesc number)

Evaluate the string.

Free the number expression content. (not the pointer itself).

Parameters
numberstruct to free

◆ FreeStringDesc()

void FreeStringDesc ( StringDesc s)

Free unit description content. (no pointer itself).

Free the String expression content. (not the pointer itself).

Parameters
sstruct to free

◆ FreeUnitDesc()

void FreeUnitDesc ( UnitDesc )

Free number description content. (no pointer itself).

Free the unit expression content. (not the pointer itself).

Parameters
unitdescstruct to free

◆ InitLua()

void InitLua ( )

Perform garbage collection.

Initialize Lua

◆ LoadCcl()

void LoadCcl ( const std::string &  filename,
const std::string &  luaArgStr = "" 
)

Initialise Lua.

◆ lua_rawlen()

size_t lua_rawlen ( lua_State *  l,
int  index 
)
inline

◆ LuaCall() [1/2]

int LuaCall ( int  narg,
int  clear,
bool  exitOnError 
)

Call a lua function

Parameters
nargNumber of arguments
clearClear the return value(s)
exitOnErrorExit the program when an error occurs
Returns
0 in success, else exit.

◆ LuaCall() [2/2]

int LuaCall ( lua_State *  L,
int  narg,
int  nresults,
int  base,
bool  exitOnError 
)

Call a lua function

Parameters
LPointer to Lua state
nargNumber of arguments
nresultsNumber of return values
baseStack index of the function to call
exitOnErrorExit the program when an error occurs
Returns
0 in success, else exit.

◆ LuaGarbageCollect()

void LuaGarbageCollect ( )

Perform lua garbage collection

◆ LuaLoadFile()

int LuaLoadFile ( const std::string &  file,
const std::string &  strArg,
bool  exitOnError 
)

Load a file and execute it

Parameters
fileFile to load and execute
nargsNumber of arguments that caller has put on the stack
Returns
0 for success, -1 if the file was not found, else exit.

◆ LuaToBoolean() [1/2]

bool LuaToBoolean ( lua_State *  l,
int  index,
int  subIndex 
)

◆ LuaToBoolean() [2/2]

bool LuaToBoolean ( lua_State *  l,
int  narg 
)

Convert lua boolean to bool. It also checks type and exits in case of error.

Parameters
lLua state.
nargArgument number.
Returns
1 for true, 0 for false from lua.

◆ LuaToFloat()

float LuaToFloat ( lua_State *  l,
int  narg 
)

Convert lua number in C float. It checks also type and exit in case of error.

Parameters
lLua state.
nargArgument number.
Returns
C number from lua.

◆ LuaToNumber() [1/2]

int LuaToNumber ( lua_State *  l,
int  index,
int  subIndex 
)

◆ LuaToNumber() [2/2]

int LuaToNumber ( lua_State *  l,
int  narg 
)

Convert lua number in C number. It checks also type and exit in case of error.

Parameters
lLua state.
nargArgument number.
Returns
C number from lua.

◆ LuaToString() [1/2]

const char* LuaToString ( lua_State *  l,
int  index,
int  subIndex 
)

◆ LuaToString() [2/2]

const char* LuaToString ( lua_State *  l,
int  narg 
)

True while config file parsing.

Convert lua string in char*. It checks also type and exit in case of error.

Note
char* could be invalidated with lua garbage collector.
Parameters
lLua state.
nargArgument number.
Returns
char* from lua.

◆ LuaToUnsignedNumber() [1/2]

unsigned int LuaToUnsignedNumber ( lua_State *  l,
int  index,
int  subIndex 
)

◆ LuaToUnsignedNumber() [2/2]

unsigned int LuaToUnsignedNumber ( lua_State *  l,
int  narg 
)

Convert lua number in C unsigned int. It checks also type and exit in case of error.

Parameters
lLua state.
nargArgument number.
Returns
C number from lua.

◆ SaveGlobal()

std::string SaveGlobal ( lua_State *  l)

◆ SavePreferences()

void SavePreferences ( )

Load ccl config file.

◆ ScriptRegister()

void ScriptRegister ( )

◆ Str2EnumVariable()

EnumVariable Str2EnumVariable ( lua_State *  l,
const char *  s 
)

Damage calculation for missile.

transform string in corresponding index.

Return enum from string about variable component.

Parameters
lLua State.
sstring to convert.
Returns
Corresponding value.
Note
Stop on error.

Variable Documentation

◆ CclInConfigFile

int CclInConfigFile

Structure to work with lua files.

◆ Damage

NumberDesc* Damage

True while config file parsing.

◆ Lua

lua_State* Lua
(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.