Commit b66e8d74 authored by alex@thinkpad's avatar alex@thinkpad
Browse files

Lua: dryos.directory.__tostring()

--HG--
branch : lua_fix
parent 61b728624841
......@@ -29,6 +29,7 @@ static int luaCB_card_index(lua_State * L);
static int luaCB_card_newindex(lua_State * L);
static int luaCB_directory_index(lua_State * L);
static int luaCB_directory_newindex(lua_State * L);
static int luaCB_directory_tostring(lua_State * L);
static int luaCB_card_image_path(lua_State * L);
const char * lua_dryos_directory_fields[] =
......@@ -92,6 +93,8 @@ static int luaCB_dryos_directory(lua_State * L)
}
lua_setfield(L, -2, "path");
lua_newtable(L);
lua_pushcfunction(L, luaCB_directory_tostring);
lua_setfield(L, -2, "__tostring");
lua_pushcfunction(L, luaCB_directory_index);
lua_setfield(L, -2, "__index");
lua_pushcfunction(L, luaCB_directory_newindex);
......@@ -479,6 +482,13 @@ static int luaCB_directory_newindex(lua_State * L)
return luaL_error(L, "'directory' type is readonly");
}
static int luaCB_directory_tostring(lua_State * L)
{
if(!lua_istable(L, 1)) return luaL_argerror(L, 1, "expected table");
lua_getfield(L, 1, "path");
return 1;
}
/// Represents a card (storage media).
// Inherits from @{directory}
// @type card
......
......@@ -232,7 +232,7 @@ function card_test()
printf("CF card (%s) present\n", dryos.cf_card.path)
printf("- free space: %d MiB\n", dryos.cf_card.free_space)
printf("- next image: %s\n", dryos.cf_card:image_path(1))
printf("- DCIM dir. : %s\n", dryos.cf_card.dcim_dir.path)
printf("- DCIM dir. : %s\n", dryos.cf_card.dcim_dir)
assert(dryos.cf_card.path == "A:/")
assert(dryos.cf_card.type == "CF")
end
......@@ -240,7 +240,7 @@ function card_test()
printf("SD card (%s) present\n", dryos.sd_card.path)
printf("- free space: %d MiB\n", dryos.sd_card.free_space)
printf("- next image: %s\n", dryos.sd_card:image_path(1))
printf("- DCIM dir. : %s\n", dryos.sd_card.dcim_dir.path)
printf("- DCIM dir. : %s\n", dryos.sd_card.dcim_dir)
assert(dryos.sd_card.path == "B:/")
assert(dryos.sd_card.type == "SD")
end
......@@ -1028,6 +1028,7 @@ function test_camera_take_pics()
-- next image path is harder to build manually, as you need to take care
-- of wrapping around (100CANON/IMG_9999.CR2 -> 101CANON/IMG_0001.CR2)
-- this is why dryos.shooting_card:image_path is preferred -- it handles these edge cases for you
assert(dryos.shooting_card.dcim_dir.path == tostring(dryos.shooting_card.dcim_dir))
local image_path_dcim =
dryos.shooting_card.dcim_dir.path ..
dryos.image_prefix ..
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment