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

src/include/script.h File Reference

#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>

Go to the source code of this file.


Classes

struct  _lua_user_data_
struct  _binop_
struct  _NumberDesc_
 for Bin operand a ?? b More...
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
}
enum  EUnit { EUnit_Ref }
 All possible value for a number. More...
enum  EString {
  EString_Lua, EString_Dir, EString_Concat, EString_String,
  EString_InverseVideo, EString_If, EString_UnitName, EString_SubString,
  EString_Line
}
 All possible value for a unit. More...
enum  ES_GameInfo { ES_GameInfo_Objectives }
 All possible value for a string. More...
enum  EnumVariable {
  VariableValue = 0, VariableMax, VariableIncrease, VariableDiff,
  VariablePercent, VariableName
}
 All possible value for a game info string. More...
enum  EnumUnit {
  UnitRefItSelf = 0, UnitRefInside, UnitRefContainer, UnitRefWorker,
  UnitRefGoal
}
typedef struct _lua_user_data_ LuaUserData
typedef struct _NumberDesc_ NumberDesc
typedef struct _UnitDesc_ UnitDesc
typedef struct _StringDesc_ StringDesc
typedef struct _binop_ BinOp
lua_State * Lua
int CclInConfigFile
NumberDescDamage
 true if gain XP by dealing damage, false if by killing.
int LuaLoadFile (const std::string &file)
int LuaCall (int narg, int clear, bool exitOnError=true)
const char * LuaToString (lua_State *l, int narg)
 True while config file parsing.
int LuaToNumber (lua_State *l, int narg)
bool LuaToBoolean (lua_State *l, int narg)
void CclGarbageCollect (int fast)
void InitCcl ()
 Perform garbage collection.
void LoadCcl (const std::string &filename)
 Initialise ccl.
void SaveCcl (CFile *file)
 Load ccl config file.
void SavePreferences ()
 Save CCL module.
int CclCommand (const std::string &command, bool exitOnError=true)
 Save user preferences.
EnumVariable Str2EnumVariable (lua_State *l, const char *s)
 Damage calculation for missile.
NumberDescCclParseNumberDesc (lua_State *l)
UnitDescCclParseUnitDesc (lua_State *l)
 Parse a number description.
StringDescCclParseStringDesc (lua_State *l)
 Parse a unit description.
StringDescNewStringDesc (const char *s)
 Parse a string description.
int EvalNumber (const NumberDesc *numberdesc)
 Create a StringDesc with const string.
CUnitEvalUnit (const UnitDesc *unitdesc)
 Evaluate the number.
std::string EvalString (const StringDesc *s)
 Evaluate the unit.
void FreeNumberDesc (NumberDesc *number)
 Evaluate the string.
void FreeUnitDesc (UnitDesc *unitdesc)
 Free number description content. (no pointer itself).
void FreeStringDesc (StringDesc *s)
 Free unit description content. (no pointer itself).

Define Documentation

#define LuaCheckArgs ( l,
args   ) 

Value:

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

#define LuaError ( l,
args   ) 

Value:

do { \
                fprintf(stdout, "%s:%d: %s: ", __FILE__, __LINE__, __func__); \
                fprintf(stdout, args); \
                fprintf(stdout, "\n"); \
                lua_pushfstring(l, args); lua_error(l); \
        } while (0)


Typedef Documentation

typedef struct _binop_ BinOp

typedef struct _lua_user_data_ LuaUserData

typedef struct _NumberDesc_ NumberDesc

Number description. Use to describe complex number in script to use when game running.

typedef struct _StringDesc_ StringDesc

String description Use to describe complex string in script to use when game running.

typedef struct _UnitDesc_ UnitDesc

Unit description Use to describe complex unit in script to use when game running.


Enumeration Type Documentation

anonymous enum

Enumerator:
LuaUnitType 
LuaSoundType 

enum ENumber

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.

Property of Unit.

enum EnumUnit

Enumeration of unit

Enumerator:
UnitRefItSelf 
UnitRefInside  unit.
UnitRefContainer  unit->Inside.
UnitRefWorker  Unit->Container.
UnitRefGoal  unit->Data.Built.Worker

unit->Goal

All possible value for a game info string.

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.

All possible value for a string.

Enumerator:
ES_GameInfo_Objectives  All Objectives of the game.

enum EString

All possible value for a unit.

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.

line n of the string.

enum EUnit

All possible value for a number.

Enumerator:
EUnit_Ref  Unit direct reference.


Function Documentation

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

Save user preferences.

Send command to ccl.

Parameters:
command Zero terminated command string.

void CclGarbageCollect ( int   ) 

Perform CCL garbage collection

Parameters:
fast set this flag to disable slow GC (during game)

NumberDesc* CclParseNumberDesc ( lua_State *  l  ) 

Return number.

Parameters:
l lua state.
Returns:
number.

StringDesc* CclParseStringDesc ( lua_State *  l  ) 

Parse a unit description.

Return String description.

Parameters:
l lua state.
Returns:
String description.

UnitDesc* CclParseUnitDesc ( lua_State *  l  ) 

Parse a number description.

Return unit referernce definition.

Parameters:
l lua state.
Returns:
unit referernce definition.

int EvalNumber ( const NumberDesc number  ) 

Create a StringDesc with const string.

compute the number expression

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

std::string EvalString ( const StringDesc s  ) 

Evaluate the unit.

compute the string expression

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

CUnit* EvalUnit ( const UnitDesc unitdesc  ) 

Evaluate the number.

compute the Unit expression

Parameters:
unitdesc struct with definition of the calculation.
Returns:
the result unit.

void FreeNumberDesc ( NumberDesc number  ) 

Evaluate the string.

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

Parameters:
number struct to free

void FreeStringDesc ( StringDesc s  ) 

Free unit description content. (no pointer itself).

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

Parameters:
s struct to free

void FreeUnitDesc ( UnitDesc  ) 

Free number description content. (no pointer itself).

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

Parameters:
unitdesc struct to free

void InitCcl (  ) 

Perform garbage collection.

Register some lua function.

void LoadCcl ( const std::string &  filename  ) 

Initialise ccl.

Load stratagus config file.

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

Call a lua function

Parameters:
narg Number of arguments
clear Clear the return value(s)
exitOnError Exit the program when an error occurs
Returns:
0 in success, else exit.

int LuaLoadFile ( const std::string &  file  ) 

Load a file and execute it

Parameters:
file File to load and execute
Returns:
0 for success, else exit.

bool LuaToBoolean ( lua_State *  l,
int  narg 
)

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

Parameters:
l Lua state.
narg Argument number.
Returns:
1 for true, 0 for false from lua.

int LuaToNumber ( lua_State *  l,
int  narg 
)

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

Parameters:
l Lua state.
narg Argument number.
Returns:
C number from lua.

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:
l Lua state.
narg Argument number.
Returns:
char* from lua.

StringDesc* NewStringDesc ( const char *  s  ) 

Parse a string description.

Create a StringDesc with const string.

Parameters:
s direct value for the StringDesc
Returns:
the new StringDesc.

void SaveCcl ( CFile file  ) 

Load ccl config file.

Save CCL Module.

Parameters:
file Save file.

void SavePreferences (  ) 

Save CCL module.

Save user preferences

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:
l Lua State.
s string to convert.
Returns:
Corresponding value.
Note:
Stop on error.


Variable Documentation

true if gain XP by dealing damage, false if by killing.

lua_State* Lua

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