LPCGame
A Simple 2d Game Engine
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
LuaC::LuaScriptLib Class Reference

#include <luacscript.h>

Static Public Member Functions

static int StackDump (lua_State *l, bool toLog=true)
 
static std::string readType (lua_State *l, int i)
 
static int requireLib (lua_State *l)
 
static int requireScript (lua_State *l)
 
static void CopyStack (lua_State *sender, lua_State *reciever, int numVals)
 
static void CopyData (lua_State *sender, int idx, lua_State *reciever)
 
static void CopyUdata (lua_State *sender, int idx, lua_State *reciever)
 
static int LuaOpenLib (lua_State *l, const std::string &metatable, const std::string &className, const luaL_reg *lib, int(*call)(lua_State *))
 
static void Add (lua_State *l, int i, const std::string &metatable)
 

Detailed Description

Class to store the various functions needed for interactions between Lua and LuaScript class along with some general Lua C utility functions

Member Function Documentation

void LuaC::LuaScriptLib::Add ( lua_State *  l,
int  i,
const std::string &  metatable 
)
static

A generic addX function for adding some userdata to the desired metatable

Parameters
lThe Lua state
iThe index of the user data, relative to top
metatableThe metatable name to register with
void LuaC::LuaScriptLib::CopyData ( lua_State *  sender,
int  idx,
lua_State *  reciever 
)
static

Type check some data in sender stack at index idx and copy it to the top of the reciever stack

Parameters
senderThe Lua state to copy from
idxThe index of the data to copy
recieverThe Lua state to copy too
void LuaC::LuaScriptLib::CopyStack ( lua_State *  sender,
lua_State *  reciever,
int  numVals 
)
static

Copy some number of entries from the sender stack to the reciever stack The function will attempt to restore metatables, but the Lua libs must already be registered in each state for it to be able to properly register numVals data will be copied from the sender to reciever and the stack ordering will be preserved, ie. start copying at the bottom most entry in sender and push onto reciever so the stack will be identical

Parameters
senderThe Lua state to transfer data from
recieverThe Lua state to transfer too
numValsThe number of entries to copy over
void LuaC::LuaScriptLib::CopyUdata ( lua_State *  sender,
int  idx,
lua_State *  reciever 
)
static

Copy some userdata using one of the UdataCopier functions, Log issue if a copier lookup failed

Parameters
senderThe Lua state to copy from
idxThe index of the data to copy
recieverThe Lua state to copy too
int LuaC::LuaScriptLib::LuaOpenLib ( lua_State *  l,
const std::string &  metatable,
const std::string &  className,
const luaL_reg *  lib,
int(*)(lua_State *)  call 
)
static

A generic luaopen_X function for opening libraries that share similar style, and have the same organization for their luaopen_X function

Parameters
lThe Lua state to register in
metatableThe name for the metatable
classNameThe name for the class table and type
libThe luaL_reg struct containing the functions and names
callThe function to load for the __call field (constructor)
std::string LuaC::LuaScriptLib::readType ( lua_State *  l,
int  i 
)
static

Read the type value of the metatable of some userdata at index

Parameters
lThe lua_State to read from
iThe index of the userdata to get the type of
Returns
The userdata type value, as a string
int LuaC::LuaScriptLib::requireLib ( lua_State *  l)
static

A function for looking up our engine libraries and loading them to a lua_State

Parameters
lThe lua_State to load the library into
Returns
Number of return values for lua to pick up
int LuaC::LuaScriptLib::requireScript ( lua_State *  l)
static

A function for looking up engine scripts and loading them to to a lua_State. An engine script is scripts/scriptname, the path will be redirected to the proper location to load from

Parameters
lThe lua_State to load the script to
Returns
Number of return values for lua to pick up
int LuaC::LuaScriptLib::StackDump ( lua_State *  l,
bool  toLog = true 
)
static

Perform a stack dump on the lua_State

Parameters
lThe lua_State to perform the stack dump on
toFileIf the stack dump should be written to Debug Log or console default is Log
Returns
Number of return values for lua to pick up

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