Skip to content

Instantly share code, notes, and snippets.

@timcharper
Created August 26, 2009 04:41
Show Gist options
  • Save timcharper/175319 to your computer and use it in GitHub Desktop.
Save timcharper/175319 to your computer and use it in GitHub Desktop.
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
#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