|
|
@ -502,6 +502,28 @@ static int l_rm(lua_State *L) |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static int ls_entry_cb(const char *name, int is_dir, uint32_t size, void *arg) |
|
|
|
|
|
{ |
|
|
|
|
|
if (is_dir) |
|
|
|
|
|
lua_print(" [DIR] %s\n", name); |
|
|
|
|
|
else |
|
|
|
|
|
lua_print(" %6u %s\n", size, name); |
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static int l_ls(lua_State *L) |
|
|
|
|
|
{ |
|
|
|
|
|
const char *path = "/"; |
|
|
|
|
|
if (lua_isstring(L, 1)) |
|
|
|
|
|
path = luaL_checkstring(L, 1); |
|
|
|
|
|
|
|
|
|
|
|
if (Rd_ListDir(path, ls_entry_cb, NULL) != RD_SUCCESS) |
|
|
|
|
|
{ |
|
|
|
|
|
lua_print("ls: cannot access '%s'\n", path); |
|
|
|
|
|
} |
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
static int luaopen_default(lua_State *L) |
|
|
static int luaopen_default(lua_State *L) |
|
|
{ |
|
|
{ |
|
|
lua_register_help(L, "help", l_help, "Show this help message"); |
|
|
lua_register_help(L, "help", l_help, "Show this help message"); |
|
|
@ -510,6 +532,7 @@ static int luaopen_default(lua_State *L) |
|
|
lua_register_help(L, "cat", l_cat, "eg: cat(\"C:a.txt\")"); |
|
|
lua_register_help(L, "cat", l_cat, "eg: cat(\"C:a.txt\")"); |
|
|
lua_register_help(L, "mv", l_mv, "eg: mv(\"C:a.txt\", \"C:b.txt\")"); |
|
|
lua_register_help(L, "mv", l_mv, "eg: mv(\"C:a.txt\", \"C:b.txt\")"); |
|
|
lua_register_help(L, "rm", l_rm, "eg: rm(\"C:a.txt\")"); |
|
|
lua_register_help(L, "rm", l_rm, "eg: rm(\"C:a.txt\")"); |
|
|
|
|
|
lua_register_help(L, "ls", l_ls, "eg: ls()"); |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|