mirror of https://github.com/bjornbytes/lovr.git
lovr.filesystem.append;
This commit is contained in:
parent
bb98fc5aec
commit
34988bcdd7
|
@ -21,6 +21,23 @@ void lovrFilesystemDestroy() {
|
|||
PHYSFS_deinit();
|
||||
}
|
||||
|
||||
int lovrFilesystemAppend(const char* path, const char* content, int size) {
|
||||
if (!PHYSFS_isInit() || !state.identity) {
|
||||
error("Can not write files until lovr.filesystem.setIdentity is called");
|
||||
}
|
||||
|
||||
// Open file
|
||||
PHYSFS_file* handle = PHYSFS_openAppend(path);
|
||||
if (!handle) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Perform write
|
||||
int bytesWritten = PHYSFS_write(handle, content, 1, size);
|
||||
PHYSFS_close(handle);
|
||||
return bytesWritten;
|
||||
}
|
||||
|
||||
int lovrFilesystemExists(const char* path) {
|
||||
return PHYSFS_exists(path);
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ typedef struct {
|
|||
|
||||
void lovrFilesystemInit(const char* arg0);
|
||||
void lovrFilesystemDestroy();
|
||||
int lovrFilesystemAppend(const char* path, const char* content, int size);
|
||||
int lovrFilesystemExists(const char* path);
|
||||
int lovrFilesystemGetExecutablePath(char* dest, unsigned int size);
|
||||
const char* lovrFilesystemGetIdentity();
|
||||
|
|
|
@ -49,6 +49,7 @@ static int filesystemLoader(lua_State* L) {
|
|||
|
||||
const luaL_Reg lovrFilesystem[] = {
|
||||
{ "init", l_lovrFilesystemInitialize },
|
||||
{ "append", l_lovrFilesystemAppend },
|
||||
{ "exists", l_lovrFilesystemExists },
|
||||
{ "getExecutablePath", l_lovrFilesystemGetExecutablePath },
|
||||
{ "getIdentity", l_lovrFilesystemGetIdentity },
|
||||
|
@ -87,6 +88,14 @@ int l_lovrFilesystemInitialize(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int l_lovrFilesystemAppend(lua_State* L) {
|
||||
size_t size;
|
||||
const char* path = luaL_checkstring(L, 1);
|
||||
const char* content = luaL_checklstring(L, 2, &size);
|
||||
lua_pushnumber(L, lovrFilesystemAppend(path, content, size));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrFilesystemExists(lua_State* L) {
|
||||
const char* path = luaL_checkstring(L, 1);
|
||||
lua_pushboolean(L, lovrFilesystemExists(path));
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
extern const luaL_Reg lovrFilesystem[];
|
||||
int l_lovrFilesystemInit(lua_State* L);
|
||||
int l_lovrFilesystemInitialize(lua_State* L);
|
||||
int l_lovrFilesystemAppend(lua_State* L);
|
||||
int l_lovrFilesystemExists(lua_State* L);
|
||||
int l_lovrFilesystemGetExecutablePath(lua_State* L);
|
||||
int l_lovrFilesystemGetIdentity(lua_State* L);
|
||||
|
|
Loading…
Reference in New Issue