Created
August 26, 2009 04:41
-
-
Save timcharper/175319 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rm lib_kernel.so lib_kernel.o | |
gcc -O2 -fno-common -c -o lib_kernel.o lib_kernel.c | |
gcc -bundle -undefined dynamic_lookup -o lib_kernel.so lib_kernel.o |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define LUA_LIB | |
#include <lua.h> | |
#include <lualib.h> | |
#include "lauxlib.h" | |
#define LUA_KERNELLIBNAME "kernel" | |
static int lib_kernel_sleep(lua_State *L) | |
{ | |
// int m = static_cast<int> (luaL_checknumber(L,1)); | |
int m = luaL_checknumber(L,1); | |
usleep(m * 1000); | |
// usleep takes nanoseconds. This converts the parameter to milliseconds. | |
// Change this as necessary. | |
// Alternatively, use 'sleep()' to treat the parameter as whole seconds. | |
return 0; | |
} | |
static const luaL_reg kernellib[] = { | |
{"sleep", lib_kernel_sleep}, | |
{NULL, NULL} | |
}; | |
LUALIB_API int luaopen_lib_kernel (lua_State *L) { | |
luaL_register(L, LUA_KERNELLIBNAME, kernellib); | |
return 1; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment