1 /* Copyright (c) 2010. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 /* SimGrid Lua bindings */
9 #include "lua_private.h"
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(lua_process, bindings, "Lua Bindings (process module)");
14 #define PROCESS_MODULE_NAME "simgrid.process"
16 /* ********************************************************************************* */
17 /* simgrid.process API */
18 /* ********************************************************************************* */
21 * \brief Makes the current process sleep for a while.
22 * \param L a Lua state
23 * \return number of values returned to Lua
25 * - Argument 1 (number): duration of the sleep
26 * - Return value (nil or string): nil in everything went ok, or a string error
27 * if case of failure ("host failure")
29 static int l_process_sleep(lua_State* L)
31 double duration = luaL_checknumber(L, 1);
32 msg_error_t res = MSG_process_sleep(duration);
39 case MSG_HOST_FAILURE:
40 lua_pushliteral(L, "host failure");
44 xbt_die("Unexpected result of MSG_process_sleep: %d, please report this bug", res);
48 static const luaL_reg process_functions[] = {
49 {"sleep", l_process_sleep},
50 /* TODO: self, create, kill, suspend, is_suspended, resume, get_name,
51 * get_pid, get_ppid, migrate
57 * \brief Registers the process functions into the table simgrid.process.
58 * \param L a lua state
60 void sglua_register_process_functions(lua_State* L)
62 luaL_openlib(L, PROCESS_MODULE_NAME, process_functions, 0);