Skip to content
Permalink
Browse files

Use lua_class_binding for iso_fs

  • Loading branch information...
TheCycoONE committed Apr 29, 2019
1 parent 9d7b17f commit 46c58e31a5240c40686ea9e930ef6d639302b60b
@@ -21,7 +21,7 @@ SOFTWARE. --]]
local pathsep = package.config:sub(1, 1)
local part_pattern = "[^" .. pathsep .. "]+"

local ISO_FS = require("ISO_FS")
local ISO_FS = require("TH").iso_fs

--! Layer for abstracting away differences in file systems
class "FileSystem"
@@ -21,6 +21,7 @@ SOFTWARE.
*/

#include "iso_fs.h"
#include "th_lua_internal.h"
#include <cstring>
#include <cstdarg>
#include <cstdlib>
@@ -560,50 +561,11 @@ int l_isofs_list_files(lua_State *L)

} // namespace

int luaopen_iso_fs(lua_State *L)
void lua_register_iso_fs(const lua_register_state* pState)
{
lua_settop(L, 1);
if(!lua_tostring(L, 1))
{
lua_pushliteral(L, "ISO_FS");
lua_replace(L, 1);
}

// Metatable
lua_createtable(L, 0, 2);
lua_pushvalue(L, -1);
lua_replace(L, luaT_environindex);

luaT_pushcclosure(L, luaT_stdgc<iso_filesystem, luaT_environindex>, 0);
lua_setfield(L, -2, "__gc");

// Methods table
luaT_pushcclosuretable(L, l_isofs_new, 0);
lua_pushvalue(L, -1);
lua_setfield(L, -3, "__index");

lua_pushcfunction(L, l_isofs_set_path_separator);
lua_setfield(L, -2, "setPathSeparator");

lua_getfield(L, LUA_REGISTRYINDEX, LUA_FILEHANDLE);
luaT_pushcclosure(L, l_isofs_set_root, 1);
lua_setfield(L, -2, "setRoot");

lua_pushcfunction(L, l_isofs_read_contents);
lua_setfield(L, -2, "readContents");

lua_pushcfunction(L, l_isofs_list_files);
lua_setfield(L, -2, "listFiles");

lua_pushvalue(L, 1);
lua_pushvalue(L, 2);
#ifndef LUA_GLOBALSINDEX
lua_pushglobaltable(L);
lua_insert(L, -3);
lua_settable(L, -3);
lua_pop(L, 1);
#else
lua_settable(L, LUA_GLOBALSINDEX);
#endif
return 1;
lua_class_binding<iso_filesystem> lcb(pState, "iso_fs", l_isofs_new, lua_metatable::iso_fs);
lcb.add_function(l_isofs_set_path_separator, "setPathSeparator");
lcb.add_function(l_isofs_set_root, "setRoot");
lcb.add_function(l_isofs_read_contents, "readContents");
lcb.add_function(l_isofs_list_files, "listFiles");
}
@@ -151,5 +151,3 @@ class iso_filesystem
static int filename_compare(const void* lhs, const void* rhs);
static void trim_identifier_version(const uint8_t* sIdent, uint8_t& iLength);
};

int luaopen_iso_fs(lua_State *L);
@@ -71,7 +71,6 @@ int lua_main_no_eval(lua_State *L)
// will call the appropriate luaopen_X function in C.
preload_lua_package(L, "rnc", luaopen_rnc);
preload_lua_package(L, "TH", luaopen_th);
preload_lua_package(L, "ISO_FS", luaopen_iso_fs);
preload_lua_package(L, "persist", luaopen_persist);
preload_lua_package(L, "sdl", luaopen_sdl);

@@ -35,6 +35,7 @@ void lua_register_movie(const lua_register_state *pState);
void lua_register_strings(const lua_register_state *pState);
void lua_register_ui(const lua_register_state *pState);
void lua_register_lfs_ext(const lua_register_state *pState);
void lua_register_iso_fs(const lua_register_state *pState);

//! Set a field on the environment table of an object
void luaT_setenvfield(lua_State *L, int index, const char *k)
@@ -284,6 +285,7 @@ int luaopen_th(lua_State *L)
lua_register_strings(pState);
lua_register_ui(pState);
lua_register_lfs_ext(pState);
lua_register_iso_fs(pState);

lua_settop(L, oState.main_table);
return 1;
@@ -52,6 +52,7 @@ enum class lua_metatable {
sprite_list,
string_proxy,
line,
iso_fs,

count
};

0 comments on commit 46c58e3

Please sign in to comment.
You can’t perform that action at this time.