mirror of https://github.com/bjornbytes/lovr.git
lovr.filesystem.write;
This commit is contained in:
parent
fff1638414
commit
5d2f4746ab
|
@ -76,3 +76,17 @@ int lovrFilesystemSetSource(const char* source) {
|
|||
int res = PHYSFS_mount(source, NULL, 0);
|
||||
return res;
|
||||
}
|
||||
|
||||
int lovrFilesystemWrite(const char* path, const char* contents, int size) {
|
||||
|
||||
// Open file
|
||||
PHYSFS_file* handle = PHYSFS_openWrite(path);
|
||||
if (!handle) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Perform write
|
||||
int bytesWritten = PHYSFS_write(handle, contents, 1, size);
|
||||
PHYSFS_close(handle);
|
||||
return bytesWritten;
|
||||
}
|
||||
|
|
|
@ -6,3 +6,4 @@ int lovrFilesystemIsDirectory(const char* path);
|
|||
int lovrFilesystemIsFile(const char* path);
|
||||
void* lovrFilesystemRead(const char* path, int* bytesRead);
|
||||
int lovrFilesystemSetSource(const char* source);
|
||||
int lovrFilesystemWrite(const char* path, const char* contents, int size);
|
||||
|
|
|
@ -55,6 +55,7 @@ const luaL_Reg lovrFilesystem[] = {
|
|||
{ "isFile", l_lovrFilesystemIsFile },
|
||||
{ "read", l_lovrFilesystemRead },
|
||||
{ "setSource", l_lovrFilesystemSetSource },
|
||||
{ "write", l_lovrFilesystemWrite },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
@ -134,3 +135,11 @@ int l_lovrFilesystemSetSource(lua_State* L) {
|
|||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrFilesystemWrite(lua_State* L) {
|
||||
int size;
|
||||
const char* path = luaL_checkstring(L, 1);
|
||||
const char* contents = luaL_checklstring(L, 2, &size);
|
||||
lua_pushnumber(L, lovrFilesystemWrite(path, contents, size));
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -10,4 +10,5 @@ int l_lovrFilesystemGetExecutablePath(lua_State* L);
|
|||
int l_lovrFilesystemIsDirectory(lua_State* L);
|
||||
int l_lovrFilesystemIsFile(lua_State* L);
|
||||
int l_lovrFilesystemRead(lua_State* L);
|
||||
int l_lovrFilesystemWrite(lua_State* L);
|
||||
int l_lovrFilesystemSetSource(lua_State* L);
|
||||
|
|
Loading…
Reference in New Issue