naev 0.11.5
nlua_file.c File Reference

Handles files. More...

#include "physfsrwops.h"
#include "nlua_file.h"
#include "log.h"
#include "nluadef.h"
#include "physfs.h"

Go to the source code of this file.

Functions

static int fileL_gc (lua_State *L)
 Frees a file.
 
static int fileL_eq (lua_State *L)
 Compares two files to see if they are the same.
 
static int fileL_new (lua_State *L)
 Opens a new file.
 
static int fileL_open (lua_State *L)
 Opens a File object.
 
static int fileL_close (lua_State *L)
 Closes a file.
 
static int fileL_read (lua_State *L)
 Reads from an open file.
 
static int fileL_write (lua_State *L)
 Reads from an open file.
 
static int fileL_seek (lua_State *L)
 Seeks in an open file.
 
static int fileL_name (lua_State *L)
 Gets the name of a file object.
 
static int fileL_mode (lua_State *L)
 Gets the mode a file is currently in.
 
static int fileL_size (lua_State *L)
 Gets the size of a file (must be open).
 
static int fileL_isopen (lua_State *L)
 Checks to see if a file is open.
 
static int fileL_filetype (lua_State *L)
 Checks to see the filetype of a path.
 
static int fileL_mkdir (lua_State *L)
 Makes a directory.
 
static int fileL_enumerate (lua_State *L)
 Returns a list of files and subdirectories of a directory.
 
static int fileL_remove (lua_State *L)
 Removes a file or directory.
 
int nlua_loadFile (nlua_env env)
 Loads the file library.
 
LuaFile_tlua_tofile (lua_State *L, int ind)
 Lua bindings to interact with files.
 
LuaFile_tluaL_checkfile (lua_State *L, int ind)
 Gets file at index or raises error if there is no file at index.
 
LuaFile_tlua_pushfile (lua_State *L, LuaFile_t file)
 Pushes a file on the stack.
 
int lua_isfile (lua_State *L, int ind)
 Checks to see if ind is a file.
 

Variables

static const luaL_Reg fileL_methods []
 

Detailed Description

Handles files.

Definition in file nlua_file.c.

Function Documentation

◆ fileL_close()

static int fileL_close ( lua_State * L)
static

Closes a file.

Lua function parameter: File file File to close. Lua return parameter: true on success.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: close

Definition at line 233 of file nlua_file.c.

◆ fileL_enumerate()

static int fileL_enumerate ( lua_State * L)
static

Returns a list of files and subdirectories of a directory.

Lua function parameter: string dir Name of the directory to check. Lua return parameter: table Table containing all the names (strings) of the subdirectories and files in the directory.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: enumerate

Definition at line 441 of file nlua_file.c.

◆ fileL_eq()

static int fileL_eq ( lua_State * L)
static

Compares two files to see if they are the same.

Lua function parameter: File f1 File 1 to compare. Lua function parameter: File f2 File 2 to compare. Lua return parameter: boolean true if both files are the same.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: __eq

Definition at line 166 of file nlua_file.c.

◆ fileL_filetype()

static int fileL_filetype ( lua_State * L)
static

Checks to see the filetype of a path.

Lua function parameter: string path Path to check to see what type it is. Lua return parameter: string What type of file it is or nil if doesn't exist.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: filetype

Definition at line 396 of file nlua_file.c.

◆ fileL_gc()

static int fileL_gc ( lua_State * L)
static

Frees a file.

Lua function parameter: File file File to free.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: __gc

Definition at line 148 of file nlua_file.c.

◆ fileL_isopen()

static int fileL_isopen ( lua_State * L)
static

Checks to see if a file is open.

Lua function parameter: File file File to check to see if is open. Lua return parameter: boolean true if the file is open, false otherwise.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: isOpen

Definition at line 382 of file nlua_file.c.

◆ fileL_mkdir()

static int fileL_mkdir ( lua_State * L)
static

Makes a directory.

Lua function parameter: string dir Name of the directory to make. Lua return parameter: boolean True on success.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: mkdir

Definition at line 422 of file nlua_file.c.

◆ fileL_mode()

static int fileL_mode ( lua_State * L)
static

Gets the mode a file is currently in.

Lua function parameter: File file File to get mode of. Lua return parameter: string Mode of the file (either 'c', 'w', 'r', or 'a')

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: getMode

Definition at line 354 of file nlua_file.c.

◆ fileL_name()

static int fileL_name ( lua_State * L)
static

Gets the name of a file object.

Lua function parameter: File file File object to get name of. Lua return parameter: string Name of the file object.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: getFilename

Definition at line 340 of file nlua_file.c.

◆ fileL_new()

static int fileL_new ( lua_State * L)
static

Opens a new file.

Lua function parameter: string path Path to open. Lua return parameter: File New file object.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: new

Definition at line 182 of file nlua_file.c.

◆ fileL_open()

static int fileL_open ( lua_State * L)
static

Opens a File object.

Lua function parameter: File File object to open. Lua function parameter:[opt="r"] mode Mode to open the file in (should be 'r', 'w', or 'a'). Lua return parameter: boolean true on success, false and an error string on failure.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: open

Definition at line 202 of file nlua_file.c.

◆ fileL_read()

static int fileL_read ( lua_State * L)
static

Reads from an open file.

Lua function parameter: File file File to read from. Lua function parameter:[opt] number bytes Number of bytes to read or all if ommitted. Lua return parameter: string Read data. Lua return parameter: number Number of bytes actually read.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: read

Definition at line 254 of file nlua_file.c.

◆ fileL_remove()

static int fileL_remove ( lua_State * L)
static

Removes a file or directory.

Lua function parameter: string path Name of the path to remove. Lua return parameter: boolean True on success.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: remove

Definition at line 466 of file nlua_file.c.

◆ fileL_seek()

static int fileL_seek ( lua_State * L)
static

Seeks in an open file.

Lua function parameter: File file File to seek in. Lua function parameter: number pos Position to seek to (from start of file). Lua return parameter: boolean true on success.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: seek

Definition at line 316 of file nlua_file.c.

◆ fileL_size()

static int fileL_size ( lua_State * L)
static

Gets the size of a file (must be open).

Lua function parameter: File file File to get the size of. Lua return parameter: number Size of the file.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: getSize

Definition at line 368 of file nlua_file.c.

◆ fileL_write()

static int fileL_write ( lua_State * L)
static

Reads from an open file.

Lua function parameter: File file File to write to. Lua function parameter: string data Data to write. Lua function parameter:[opt] number bytes Number of bytes to write.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: write

Definition at line 284 of file nlua_file.c.

◆ lua_isfile()

int lua_isfile ( lua_State * L,
int ind )

Checks to see if ind is a file.

Parameters
LLua state to check.
indIndex position to check.
Returns
1 if ind is a file.

Definition at line 126 of file nlua_file.c.

◆ lua_pushfile()

LuaFile_t * lua_pushfile ( lua_State * L,
LuaFile_t file )

Pushes a file on the stack.

Parameters
LLua state to push file into.
fileFile to push.
Returns
Newly pushed file.

Definition at line 111 of file nlua_file.c.

◆ lua_tofile()

LuaFile_t * lua_tofile ( lua_State * L,
int ind )

Lua bindings to interact with files.

Note
The API here is designed to be compatible with that of LÖVE.

Lua module: file

Gets file at index.

Parameters
LLua state to get file from.
indIndex position to find the file.
Returns
File found at the index in the state.

Definition at line 86 of file nlua_file.c.

◆ luaL_checkfile()

LuaFile_t * luaL_checkfile ( lua_State * L,
int ind )

Gets file at index or raises error if there is no file at index.

Parameters
LLua state to get file from.
indIndex position to find file.
Returns
File found at the index in the state.

Definition at line 97 of file nlua_file.c.

◆ nlua_loadFile()

int nlua_loadFile ( nlua_env env)

Loads the file library.

Parameters
envEnvironment to load file library into.
Returns
0 on success.

Definition at line 66 of file nlua_file.c.

Variable Documentation

◆ fileL_methods

const luaL_Reg fileL_methods[]
static
Initial value:
= {
{ "__gc", fileL_gc },
{ "__eq", fileL_eq },
{ "new", fileL_new },
{ "open", fileL_open },
{ "close", fileL_close },
{ "read", fileL_read },
{ "write", fileL_write },
{ "seek", fileL_seek },
{ "getFilename", fileL_name },
{ "getMode", fileL_mode },
{ "getSize", fileL_size },
{ "isOpen", fileL_isopen },
{ "filetype", fileL_filetype },
{ "mkdir", fileL_mkdir },
{ "enumerate", fileL_enumerate },
{ "remove", fileL_remove },
{0,0}
}
static int fileL_close(lua_State *L)
Closes a file.
Definition nlua_file.c:233
static int fileL_seek(lua_State *L)
Seeks in an open file.
Definition nlua_file.c:316
static int fileL_write(lua_State *L)
Reads from an open file.
Definition nlua_file.c:284
static int fileL_size(lua_State *L)
Gets the size of a file (must be open).
Definition nlua_file.c:368
static int fileL_enumerate(lua_State *L)
Returns a list of files and subdirectories of a directory.
Definition nlua_file.c:441
static int fileL_new(lua_State *L)
Opens a new file.
Definition nlua_file.c:182
static int fileL_eq(lua_State *L)
Compares two files to see if they are the same.
Definition nlua_file.c:166
static int fileL_isopen(lua_State *L)
Checks to see if a file is open.
Definition nlua_file.c:382
static int fileL_gc(lua_State *L)
Frees a file.
Definition nlua_file.c:148
static int fileL_mkdir(lua_State *L)
Makes a directory.
Definition nlua_file.c:422
static int fileL_open(lua_State *L)
Opens a File object.
Definition nlua_file.c:202
static int fileL_read(lua_State *L)
Reads from an open file.
Definition nlua_file.c:254
static int fileL_remove(lua_State *L)
Removes a file or directory.
Definition nlua_file.c:466
static int fileL_name(lua_State *L)
Gets the name of a file object.
Definition nlua_file.c:340
static int fileL_mode(lua_State *L)
Gets the mode a file is currently in.
Definition nlua_file.c:354
static int fileL_filetype(lua_State *L)
Checks to see the filetype of a path.
Definition nlua_file.c:396

File metatable methods.

Definition at line 40 of file nlua_file.c.