Dauphine  0.1
A platforming/stealth game in a medieval fantasy setting, developed with SDL2.
Public Member Functions | Private Member Functions | Private Attributes | List of all members
LuaScript Class Reference

Parses lua scripts into C++. More...

#include <LuaScript.h>

Public Member Functions

 LuaScript (const std::string &filename_)
 The constructor. More...
 
virtual ~LuaScript ()
 The destructor. More...
 
template<typename T >
unlua_get (const std::string &variableName_)
 Gets value of desired variable. More...
 
std::vector< int > unlua_getIntVector (const std::string &name_)
 Gets an int vector. More...
 
std::vector< std::string > unlua_getTableKeys (const std::string &name_)
 Gets the keys from a table. More...
 

Private Member Functions

void unlua_clean ()
 
bool unlua_getToStack (const std::string &variableName_)
 Validates existance of the variable. More...
 
template<typename T >
unlua_getValue (const std::string &variableName_)
 Gets a T type value from lua script. More...
 
template<typename T >
unlua_getDefault ()
 Gets a default value. More...
 

Private Attributes

lua_State * luaState
 The lua state. More...
 
int level
 Current level. More...
 

Detailed Description

Parses lua scripts into C++.

Constructor & Destructor Documentation

LuaScript::LuaScript ( const std::string &  filename_)

The constructor.

Initializes a new lua state, and loads the desired script.

Parameters
filename_: Path to the desired script, i.e. "lua/level1/Player.lua".
Todo:
Log an error message for different lua error codes.
LuaScript::~LuaScript ( )
virtual

The destructor.

Closes the lua state, if open.

Member Function Documentation

template<typename T >
T LuaScript::unlua_get ( const std::string &  variableName_)

Gets value of desired variable.

Template for the different get methods, which recieve a different type of value.

Parameters
variableName_: The varaible you want to get a value from.
Returns
The T value stored in 'variableName_' inside the lua script.
template<typename T >
T LuaScript::unlua_getDefault ( )
private

Gets a default value.

Returns
Value 0 or a string "null", depending on how it is called.
std::vector< int > LuaScript::unlua_getIntVector ( const std::string &  name_)

Gets an int vector.

Parameters
name_: The table which contains the int vector.
Returns
An int vector, containing all the ints inside the 'name_' array from the lua script.
std::vector< std::string > LuaScript::unlua_getTableKeys ( const std::string &  name_)

Gets the keys from a table.

Parameters
name_: The name of the table.
Returns
A string vector, containing all the keys from inside the 'name_' table from the lua script.
bool LuaScript::unlua_getToStack ( const std::string &  variableName_)
private

Validates existance of the variable.

Checks where the 'variableName_' variable exists inside the lua script.

Parameters
variableName_: The varaible you want to get a value from.
Returns
True for success, false for failure to get variable.
template<typename T >
T LuaScript::unlua_getValue ( const std::string &  variableName_)
private

Gets a T type value from lua script.

Parameters
variableName_: The varaible you want to get a value from.
Returns
T type value.

Member Data Documentation

int LuaScript::level
private

Current level.

lua_State* LuaScript::luaState
private

The lua state.


The documentation for this class was generated from the following files: