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

Lua: unify menu.get and menu.gets (using an optional argument for menu.get)

--HG--
branch : lua_fix
parent 7d5284a1ebeb
......@@ -186,29 +186,27 @@ static int get_index_for_choices(struct menu_entry * menu_entry, const char * va
/// Get 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
// @treturn int the value of the menu entry (current selection)
// @tparam[opt] string as_string pass empty string "" to get the result as string (default is int)
// @treturn ?int|string the value of the menu entry (current selection)
// @function get
static int luaCB_menu_get(lua_State * L)
{
LUA_PARAM_STRING(menu, 1);
LUA_PARAM_STRING(entry, 2);
lua_pushinteger(L, menu_get_value_from_script(menu, entry));
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);
LUA_PARAM_STRING_OPTIONAL(as_string, 3, NULL);
if (as_string)
{
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);
}
else
{
/* fixme: error checking is not done */
lua_pushinteger(L, menu_get_value_from_script(menu, entry));
}
return 1;
}
......@@ -852,7 +850,6 @@ 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,16 +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"))
assert(menu.gets("Expo", "Picture Style") == "Portrait")
assert(menu.get("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")
assert(menu.get("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
assert(menu.get("Expo", "Picture Style", "") == "Landscape") -- old selection should not change
msleep(1000)
assert(menu.select("Overlay"))
......@@ -281,12 +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")
assert(menu.get("Shoot", "Advanced Bracket", "") == "OFF")
msleep(1000)
assert(menu.set("Shoot", "Intervalometer", 0))
assert(menu.get("Shoot", "Intervalometer") == 0)
assert(menu.gets("Shoot", "Intervalometer") == "OFF")
assert(menu.get("Shoot", "Intervalometer", "") == "OFF")
msleep(1000)
-- move to Intervalometer menu
......@@ -306,25 +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")
assert(menu.get("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")
assert(menu.get("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")
assert(menu.get("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")
assert(menu.get("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