Lutok 0.5
Loading...
Searching...
No Matches
Functions
operations.hpp File Reference

Extra generic functions to interact with Lua. More...

#include <map>
#include <string>
#include <vector>
#include <lutok/state.hpp>

Go to the source code of this file.

Functions

void lutok::create_module (state &, const std::string &, const std::map< std::string, cxx_function > &)
 Creates a module: i.e.
 
unsigned int lutok::do_file (state &, const std::string &, const int, const int, const int)
 Loads and processes a Lua file.
 
unsigned int lutok::do_string (state &, const std::string &, const int, const int, const int)
 Processes a Lua script.
 
void lutok::eval (state &, const std::string &, const int)
 Convenience function to evaluate a Lua expression.
 

Detailed Description

Extra generic functions to interact with Lua.

Function Documentation

◆ create_module()

void lutok::create_module ( state s,
const std::string &  name,
const std::map< std::string, cxx_function > &  members 
)

Creates a module: i.e.

a table with a set of methods in it.

Parameters
sThe Lua state.
nameThe name of the module to create.
membersThe list of member functions to add to the module.

◆ do_file()

unsigned int lutok::do_file ( state s,
const std::string &  file,
const int  nargs,
const int  nresults,
const int  errfunc 
)

Loads and processes a Lua file.

This is a replacement for luaL_dofile but with proper error reporting and stack control.

Parameters
sThe Lua state.
fileThe file to load.
nargsThe number of arguments on the stack to pass to the file.
nresultsThe number of results to expect; -1 for any.
errfuncIf not 0, index of a function in the stack to act as an error handler.
Returns
The number of results left on the stack.
Exceptions
errorIf there is a problem processing the file.

◆ do_string()

unsigned int lutok::do_string ( state s,
const std::string &  str,
const int  nargs,
const int  nresults,
const int  errfunc 
)

Processes a Lua script.

This is a replacement for luaL_dostring but with proper error reporting and stack control.

Parameters
sThe Lua state.
strThe string to process.
nargsThe number of arguments on the stack to pass to the chunk.
nresultsThe number of results to expect; -1 for any.
errfuncIf not 0, index of a function in the stack to act as an error handler.
Returns
The number of results left on the stack.
Exceptions
errorIf there is a problem processing the string.

◆ eval()

void lutok::eval ( state s,
const std::string &  expression,
const int  nresults 
)

Convenience function to evaluate a Lua expression.

Parameters
sThe Lua state.
expressionThe textual expression to evaluate.
nresultsThe number of results to leave on the stack. Must be positive.
Exceptions
api_errorIf there is a problem evaluating the expression.