|
|
|
@ -1991,6 +1991,26 @@ static const LuaWrapper::FunctionReg dfhack_filesystem_module[] = {
|
|
|
|
|
{NULL, NULL}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int filesystem_listdir(lua_State *L)
|
|
|
|
|
{
|
|
|
|
|
luaL_checktype(L,1,LUA_TSTRING);
|
|
|
|
|
std::string dir=lua_tostring(L,1);
|
|
|
|
|
std::vector<std::string> files;
|
|
|
|
|
DFHack::Filesystem::listdir(dir, files);
|
|
|
|
|
lua_newtable(L);
|
|
|
|
|
for(int i=0;i<files.size();i++)
|
|
|
|
|
{
|
|
|
|
|
lua_pushinteger(L,i+1);
|
|
|
|
|
lua_pushstring(L,files[i].c_str());
|
|
|
|
|
lua_settable(L,-3);
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const luaL_Reg dfhack_filesystem_funcs[] = {
|
|
|
|
|
{"listdir", filesystem_listdir},
|
|
|
|
|
{NULL, NULL}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/***** Internal module *****/
|
|
|
|
|
|
|
|
|
@ -2283,21 +2303,6 @@ static int internal_diffscan(lua_State *L)
|
|
|
|
|
lua_pushnil(L);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
static int internal_getDir(lua_State *L)
|
|
|
|
|
{
|
|
|
|
|
luaL_checktype(L,1,LUA_TSTRING);
|
|
|
|
|
std::string dir=lua_tostring(L,1);
|
|
|
|
|
std::vector<std::string> files;
|
|
|
|
|
DFHack::getdir(dir,files);
|
|
|
|
|
lua_newtable(L);
|
|
|
|
|
for(int i=0;i<files.size();i++)
|
|
|
|
|
{
|
|
|
|
|
lua_pushinteger(L,i+1);
|
|
|
|
|
lua_pushstring(L,files[i].c_str());
|
|
|
|
|
lua_settable(L,-3);
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int internal_runCommand(lua_State *L)
|
|
|
|
|
{
|
|
|
|
@ -2384,7 +2389,7 @@ static const luaL_Reg dfhack_internal_funcs[] = {
|
|
|
|
|
{ "memcmp", internal_memcmp },
|
|
|
|
|
{ "memscan", internal_memscan },
|
|
|
|
|
{ "diffscan", internal_diffscan },
|
|
|
|
|
{ "getDir", internal_getDir },
|
|
|
|
|
{ "getDir", filesystem_listdir },
|
|
|
|
|
{ "runCommand", internal_runCommand },
|
|
|
|
|
{ "getModifiers", internal_getModifiers },
|
|
|
|
|
{ NULL, NULL }
|
|
|
|
@ -2412,6 +2417,6 @@ void OpenDFHackApi(lua_State *state)
|
|
|
|
|
OpenModule(state, "buildings", dfhack_buildings_module, dfhack_buildings_funcs);
|
|
|
|
|
OpenModule(state, "constructions", dfhack_constructions_module);
|
|
|
|
|
OpenModule(state, "screen", dfhack_screen_module, dfhack_screen_funcs);
|
|
|
|
|
OpenModule(state, "filesystem", dfhack_filesystem_module);
|
|
|
|
|
OpenModule(state, "filesystem", dfhack_filesystem_module, dfhack_filesystem_funcs);
|
|
|
|
|
OpenModule(state, "internal", dfhack_internal_module, dfhack_internal_funcs);
|
|
|
|
|
}
|
|
|
|
|