summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2013-08-11 19:18:16 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2013-08-11 19:18:16 +0200
commitd759bd371050d933a13c3e0b283313f44b7da425 (patch)
treefc975fd889c9822c426323bcc2362269f9fe5123 /utils
parent4aae8274b3a614de008985b493cd0162fc2557cb (diff)
downloadrockbox-d759bd371050d933a13c3e0b283313f44b7da425.tar.gz
rockbox-d759bd371050d933a13c3e0b283313f44b7da425.zip
hwstub: add atexit and exit stub function to DEV
Change-Id: I17cfe52de3f6f546a46ace3252113024625f15d1
Diffstat (limited to 'utils')
-rw-r--r--utils/hwstub/tools/hwstub_shell.cpp35
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)
211 return 0; 211 return 0;
212} 212}
213 213
214int my_lua_atexit(lua_State *state)
215{
216 int n = lua_gettop(state);
217 if(n != 1)
218 luaL_error(state, "atexit takes one argument");
219 const char *arg = luaL_checkstring(state, 1);
220 int ret = -1;
221 if(strcmp(arg, "nop") == 0)
222 ret = hwstub_atexit(&g_hwdev, HWSTUB_ATEXIT_NOP);
223 else if(strcmp(arg, "reboot") == 0)
224 ret = hwstub_atexit(&g_hwdev, HWSTUB_ATEXIT_REBOOT);
225 else if(strcmp(arg, "off") == 0)
226 ret = hwstub_atexit(&g_hwdev, HWSTUB_ATEXIT_OFF);
227 else
228 luaL_error(state, "unknown atexit method '%s'", arg);
229 if(ret < 0)
230 luaL_error(state, "fail to set atexit method");
231 return 0;
232}
233
214int my_lua_exit(lua_State *state) 234int my_lua_exit(lua_State *state)
215{ 235{
236 if(hwstub_exit(&g_hwdev) < 0)
237 luaL_error(state, "fail to exit hwstub");
238 return 0;
239}
240
241int my_lua_quit(lua_State *state)
242{
216 g_exit = true; 243 g_exit = true;
217 return 0; 244 return 0;
218} 245}
@@ -310,6 +337,10 @@ bool my_lua_import_hwstub()
310 lua_setfield(g_lua, -2, "write32"); 337 lua_setfield(g_lua, -2, "write32");
311 lua_pushcclosure(g_lua, my_lua_printlog, 0); 338 lua_pushcclosure(g_lua, my_lua_printlog, 0);
312 lua_setfield(g_lua, -2, "print_log"); 339 lua_setfield(g_lua, -2, "print_log");
340 lua_pushcclosure(g_lua, my_lua_atexit, 0);
341 lua_setfield(g_lua, -2, "atexit");
342 lua_pushcclosure(g_lua, my_lua_exit, 0);
343 lua_setfield(g_lua, -2, "exit");
313 344
314 lua_setfield(g_lua, -2, "dev"); 345 lua_setfield(g_lua, -2, "dev");
315 346
@@ -347,10 +378,10 @@ bool my_lua_import_hwstub()
347 lua_pushcfunction(g_lua, my_lua_help); 378 lua_pushcfunction(g_lua, my_lua_help);
348 lua_setglobal(g_lua, "help"); 379 lua_setglobal(g_lua, "help");
349 380
350 lua_pushcfunction(g_lua, my_lua_exit); 381 lua_pushcfunction(g_lua, my_lua_quit);
351 lua_setglobal(g_lua, "exit"); 382 lua_setglobal(g_lua, "exit");
352 383
353 lua_pushcfunction(g_lua, my_lua_exit); 384 lua_pushcfunction(g_lua, my_lua_quit);
354 lua_setglobal(g_lua, "quit"); 385 lua_setglobal(g_lua, "quit");
355 386
356 if(lua_gettop(g_lua) != oldtop) 387 if(lua_gettop(g_lua) != oldtop)