Commit 43fb6c33 authored by alex@thinkpad's avatar alex@thinkpad
Browse files

Lua: menu.gets (to get menu value as string)

api_test.lua updated as well

--HG--
branch : lua_fix
parent 02e0675ae05e
......@@ -196,6 +196,22 @@ static int luaCB_menu_get(lua_State * L)
return 1;
}
/// Get the value of some existing ML menu entry, as string.
// @tparam string menu name of the parent menu ('Audio', 'Expo', 'Overlay', 'Shoot', 'Movie', etc)
// @tparam string entry name of the menu entry
// @treturn string the value of the menu entry (current selection)
// @function gets
static int luaCB_menu_gets(lua_State * L)
{
LUA_PARAM_STRING(menu, 1);
LUA_PARAM_STRING(entry, 2);
struct menu_display_info info;
char * str = menu_get_str_value_from_script(menu, entry, &info);
if (!str) return luaL_error(L, "menu not found");
lua_pushstring(L, str);
return 1;
}
/// Set the value of some existing ML menu entry.
// @tparam string menu name of the parent menu ('Audio', 'Expo', 'Overlay', 'Shoot', 'Movie', etc).
// @tparam string entry name of the menu entry.
......@@ -836,6 +852,7 @@ static const char * lua_menu_fields[] =
const luaL_Reg menulib[] =
{
{"get", luaCB_menu_get},
{"gets", luaCB_menu_gets},
{"set", luaCB_menu_set},
{"open", luaCB_menu_open},
{"close", luaCB_menu_close},
......
......@@ -249,12 +249,16 @@ function test_menu()
-- picture styles should be set-able as string
-- numeric works too, as it sets the internal index
assert(menu.set("Expo", "Picture Style", "Portrait"))
msleep(1000)
assert(menu.set("Expo", "Picture Style", "Landscape"))
assert(menu.gets("Expo", "Picture Style") == "Portrait")
msleep(1000)
assert(menu.set("Expo", "Picture Style", 5)) -- OK, selects Neutral
-- skip string test, as other camera models may use different indices
msleep(1000)
assert(menu.set("Expo", "Picture Style", "Landscape"))
assert(menu.gets("Expo", "Picture Style") == "Landscape")
msleep(1000)
assert(not menu.set("Expo", "Picture Style", 1234)) -- should fail, out of range
assert(menu.gets("Expo", "Picture Style") == "Landscape") -- old selection should not change
msleep(1000)
assert(menu.select("Overlay"))
......@@ -277,10 +281,12 @@ function test_menu()
-- turning off should be straightforward
assert(menu.set("Shoot", "Advanced Bracket", "OFF"))
assert(menu.get("Shoot", "Advanced Bracket") == 0)
assert(menu.gets("Shoot", "Advanced Bracket") == "OFF")
msleep(1000)
assert(menu.set("Shoot", "Intervalometer", 0))
assert(menu.get("Shoot", "Intervalometer") == 0)
assert(menu.gets("Shoot", "Intervalometer") == "OFF")
msleep(1000)
-- move to Intervalometer menu
......@@ -300,21 +306,25 @@ function test_menu()
-- smaller ranges are OK for trying every single value
assert(menu.set("Intervalometer", "Take a pic every", "1m30s"))
assert(menu.get("Intervalometer", "Take a pic every") == 90)
assert(menu.gets("Intervalometer", "Take a pic every") == "1m30s")
msleep(1000)
-- actual string will be 10s
assert(menu.set("Intervalometer", "Take a pic every", "10"))
assert(menu.get("Intervalometer", "Take a pic every") == 10)
assert(menu.gets("Intervalometer", "Take a pic every") == "10s")
msleep(1000)
-- integer should work as well - e.g. 1m10s should work now
assert(menu.set("Intervalometer", "Take a pic every", 70))
assert(menu.get("Intervalometer", "Take a pic every") == 70)
assert(menu.gets("Intervalometer", "Take a pic every") == "1m10s")
msleep(1000)
-- out of range, should fail
assert(not menu.set("Intervalometer", "Take a pic every", 7000000))
assert(menu.get("Intervalometer", "Take a pic every") == 70)
assert(menu.gets("Intervalometer", "Take a pic every") == "1m10s")
msleep(1000)
-- exit submenu
......
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