diff options
author | Amaury Pouly <amaury.pouly@gmail.com> | 2013-08-11 19:18:16 +0200 |
---|---|---|
committer | Amaury Pouly <amaury.pouly@gmail.com> | 2013-08-11 19:18:16 +0200 |
commit | d759bd371050d933a13c3e0b283313f44b7da425 (patch) | |
tree | fc975fd889c9822c426323bcc2362269f9fe5123 /utils/hwstub/tools | |
parent | 4aae8274b3a614de008985b493cd0162fc2557cb (diff) | |
download | rockbox-d759bd371050d933a13c3e0b283313f44b7da425.tar.gz rockbox-d759bd371050d933a13c3e0b283313f44b7da425.zip |
hwstub: add atexit and exit stub function to DEV
Change-Id: I17cfe52de3f6f546a46ace3252113024625f15d1
Diffstat (limited to 'utils/hwstub/tools')
-rw-r--r-- | utils/hwstub/tools/hwstub_shell.cpp | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/utils/hwstub/tools/hwstub_shell.cpp b/utils/hwstub/tools/hwstub_shell.cpp index 86824b680c..0130828043 100644 --- a/utils/hwstub/tools/hwstub_shell.cpp +++ b/utils/hwstub/tools/hwstub_shell.cpp @@ -211,8 +211,35 @@ int my_lua_printlog(lua_State *state) return 0; } +int my_lua_atexit(lua_State *state) +{ + int n = lua_gettop(state); + if(n != 1) + luaL_error(state, "atexit takes one argument"); + const char *arg = luaL_checkstring(state, 1); + int ret = -1; + if(strcmp(arg, "nop") == 0) + ret = hwstub_atexit(&g_hwdev, HWSTUB_ATEXIT_NOP); + else if(strcmp(arg, "reboot") == 0) + ret = hwstub_atexit(&g_hwdev, HWSTUB_ATEXIT_REBOOT); + else if(strcmp(arg, "off") == 0) + ret = hwstub_atexit(&g_hwdev, HWSTUB_ATEXIT_OFF); + else + luaL_error(state, "unknown atexit method '%s'", arg); + if(ret < 0) + luaL_error(state, "fail to set atexit method"); + return 0; +} + int my_lua_exit(lua_State *state) { + if(hwstub_exit(&g_hwdev) < 0) + luaL_error(state, "fail to exit hwstub"); + return 0; +} + +int my_lua_quit(lua_State *state) +{ g_exit = true; return 0; } @@ -310,6 +337,10 @@ bool my_lua_import_hwstub() lua_setfield(g_lua, -2, "write32"); lua_pushcclosure(g_lua, my_lua_printlog, 0); lua_setfield(g_lua, -2, "print_log"); + lua_pushcclosure(g_lua, my_lua_atexit, 0); + lua_setfield(g_lua, -2, "atexit"); + lua_pushcclosure(g_lua, my_lua_exit, 0); + lua_setfield(g_lua, -2, "exit"); lua_setfield(g_lua, -2, "dev"); @@ -347,10 +378,10 @@ bool my_lua_import_hwstub() lua_pushcfunction(g_lua, my_lua_help); lua_setglobal(g_lua, "help"); - lua_pushcfunction(g_lua, my_lua_exit); + lua_pushcfunction(g_lua, my_lua_quit); lua_setglobal(g_lua, "exit"); - lua_pushcfunction(g_lua, my_lua_exit); + lua_pushcfunction(g_lua, my_lua_quit); lua_setglobal(g_lua, "quit"); if(lua_gettop(g_lua) != oldtop) |