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

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 231 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 435 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 164 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 394 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 146 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 380 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 420 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 352 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 338 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 180 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 200 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 252 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 314 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 366 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 282 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 124 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 109 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 84 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 95 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 64 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 },
{0,0}
}
static int fileL_close(lua_State *L)
Closes a file.
Definition: nlua_file.c:231
static int fileL_seek(lua_State *L)
Seeks in an open file.
Definition: nlua_file.c:314
static int fileL_write(lua_State *L)
Reads from an open file.
Definition: nlua_file.c:282
static int fileL_size(lua_State *L)
Gets the size of a file (must be open).
Definition: nlua_file.c:366
static int fileL_enumerate(lua_State *L)
Returns a list of files and subdirectories of a directory.
Definition: nlua_file.c:435
static int fileL_new(lua_State *L)
Opens a new file.
Definition: nlua_file.c:180
static int fileL_eq(lua_State *L)
Compares two files to see if they are the same.
Definition: nlua_file.c:164
static int fileL_isopen(lua_State *L)
Checks to see if a file is open.
Definition: nlua_file.c:380
static int fileL_gc(lua_State *L)
Frees a file.
Definition: nlua_file.c:146
static int fileL_mkdir(lua_State *L)
Makes a directory.
Definition: nlua_file.c:420
static int fileL_open(lua_State *L)
Opens a File object.
Definition: nlua_file.c:200
static int fileL_read(lua_State *L)
Reads from an open file.
Definition: nlua_file.c:252
static int fileL_name(lua_State *L)
Gets the name of a file object.
Definition: nlua_file.c:338
static int fileL_mode(lua_State *L)
Gets the mode a file is currently in.
Definition: nlua_file.c:352
static int fileL_filetype(lua_State *L)
Checks to see the filetype of a path.
Definition: nlua_file.c:394

File metatable methods.

Definition at line 39 of file nlua_file.c.