axmol/cocos/scripting/lua-bindings/manual/lua_extensions.c

38 lines
721 B
C
Raw Normal View History

2014-03-10 14:04:58 +08:00
#include "lua_extensions.h"
#if __cplusplus
extern "C" {
#endif
// socket
#include "luasocket/luasocket.h"
#include "luasocket/mime.h"
#include "luasocket/socket_scripts.h"
static luaL_Reg luax_exts[] = {
{"socket.core", luaopen_socket_core},
{"mime.core", luaopen_mime_core},
{NULL, NULL}
};
void luaopen_lua_extensions(lua_State *L)
{
// load extensions
luaL_Reg* lib = luax_exts;
lua_getglobal(L, "package");
lua_getfield(L, -1, "preload");
for (; lib->func; lib++)
{
lua_pushcfunction(L, lib->func);
lua_setfield(L, -2, lib->name);
}
lua_pop(L, 2);
// load extensions script
luaopen_socket_scripts(L);
}
#if __cplusplus
} // extern "C"
#endif