The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Classes | Functions
lua_fileops Namespace Reference

Classes

class  lua_filestream
 

Functions

static std::string get_calling_file (lua_State *L)
 
static bool resolve_filename (std::string &filename, std::string currentdir, std::string *rel=nullptr)
 resolves filename to an absolute path More...
 
int intf_have_file (lua_State *L)
 Checks if a file exists (not necessarily a Lua script). More...
 
int intf_read_file (lua_State *L)
 Reads a file into a string, or a directory into a list of files therein. More...
 
int load_file (lua_State *L)
 Loads a Lua file and pushes the contents on the stack. More...
 

Function Documentation

static std::string lua_fileops::get_calling_file ( lua_State L)
static
int lua_fileops::intf_have_file ( lua_State L)

Checks if a file exists (not necessarily a Lua script).

  • Arg 1: string containing the file name.
  • Arg 2: if true, the file must be a real file and not a directory
  • Ret 1: boolean

Definition at line 124 of file lua_fileops.cpp.

References get_calling_file(), filesystem::is_directory(), lua_pushboolean(), luaL_checkstring, luaW_toboolean(), and resolve_filename().

Referenced by lua_kernel_base::lua_kernel_base().

int lua_fileops::intf_read_file ( lua_State L)

Reads a file into a string, or a directory into a list of files therein.

  • Arg 1: string containing the file name.
  • Ret 1: string

Definition at line 142 of file lua_fileops.cpp.

References b, get_calling_file(), filesystem::get_files_in_dir(), filesystem::is_directory(), filesystem::istream_file(), lua_push(), lua_pushnumber(), lua_setfield(), luaL_addsize, luaL_argerror(), luaL_buffinit(), luaL_checkstring, luaL_error(), luaL_prepbuffsize(), luaL_pushresult(), p, resolve_filename(), and utf8::size().

Referenced by lua_kernel_base::lua_kernel_base().

int lua_fileops::load_file ( lua_State L)

Loads a Lua file and pushes the contents on the stack.

  • Arg 1: string containing the file name.
  • Ret 1: the loaded contents of the file

Definition at line 231 of file lua_fileops.cpp.

References get_calling_file(), lua_error(), lua_fileops::lua_filestream::lua_loadfile(), lua_remove, luaL_argerror(), luaL_checkstring, p, and resolve_filename().

Referenced by lua_kernel_base::intf_dofile(), lua_kernel_base::intf_require(), and application_lua_kernel::load_script_from_file().

static bool lua_fileops::resolve_filename ( std::string &  filename,
std::string  currentdir,
std::string *  rel = nullptr 
)
static

resolves filename to an absolute path

Returns
true if the filename was sucessfully resolved.

Definition at line 65 of file lua_fileops.cpp.

References gui2::event::find(), filesystem::get_wml_location(), and p.

Referenced by intf_have_file(), intf_read_file(), and load_file().