Exemplo n.º 1
0
void LuaAreaStore::Register(lua_State *L)
{
	lua_newtable(L);
	int methodtable = lua_gettop(L);
	luaL_newmetatable(L, className);
	int metatable = lua_gettop(L);

	lua_pushliteral(L, "__metatable");
	lua_pushvalue(L, methodtable);
	lua_settable(L, metatable);  // hide metatable from Lua getmetatable()

	lua_pushliteral(L, "__index");
	lua_pushvalue(L, methodtable);
	lua_settable(L, metatable);

	lua_pushliteral(L, "__gc");
	lua_pushcfunction(L, gc_object);
	lua_settable(L, metatable);

	lua_pop(L, 1);  // drop metatable

	luaL_openlib(L, 0, methods, 0);  // fill methodtable
	lua_pop(L, 1);  // drop methodtable

	// Can be created from Lua (AreaStore())
	lua_register(L, className, create_object);
}
Exemplo n.º 2
0
/*-------------------------------------------------------------------------*\
* Setup basic stuff.
\*-------------------------------------------------------------------------*/
static int base_open(lua_State *L) {
    if (socket_open()) {
        /* export functions (and leave namespace table on top of stack) */
#if LUA_VERSION_NUM > 501 && !defined(LUA_COMPAT_MODULE)
        lua_newtable(L);
        luaL_setfuncs(L, func, 0);
#else
        luaL_openlib(L, "socket", func, 0);
#endif
#ifdef LUASOCKET_DEBUG
        lua_pushstring(L, "_DEBUG");
        lua_pushboolean(L, 1);
        lua_rawset(L, -3);
#endif
        /* make version string available to scripts */
        lua_pushstring(L, "_VERSION");
        lua_pushstring(L, LUASOCKET_VERSION);
        lua_rawset(L, -3);
        return 1;
    } else {
        lua_pushstring(L, "unable to initialize library");
        lua_error(L);
        return 0;
    }
}
Exemplo n.º 3
0
LUALIB_API int luaopen_base (lua_State *L) {
  base_open(L);
  luaL_openlib(L, LUA_COLIBNAME, co_funcs, 0);
  lua_newtable(L);
  lua_setglobal(L, REQTAB);
  return 0;
}
Exemplo n.º 4
0
LUALIB_API int luaopen_debug (lua_State *L) {
  luaL_openlib(L, LUA_DBLIBNAME, dblib, 0);
  lua_pushliteral(L, "_TRACEBACK");
  lua_pushcfunction(L, errorfb);
  lua_settable(L, LUA_GLOBALSINDEX);
  return 1;
}
Exemplo n.º 5
0
/// @brief Binds the graphics system to the Lua scripting system
void luaopen_graphics (lua_State * L)
{
	assert(L != 0);

	RegisterUserType(L, "Font", 0, 0, GC_Font);
	RegisterUserType(L, "Picture", 0, 0, GC_Picture);
	RegisterUserType(L, "TextImage", 0, 0, GC_TextImage);

	const luaL_reg RenderFuncs[] = {
		M_(SetupGraphics),
		M_(CloseGraphics),
		M_(SetVideoMode),
		M_(GetVideoSize),
		M_(PrepareFrame),
		M_(DrawFrame),
		M_(LoadPicture),
		M_(DrawPicture),
		M_(SetPictureTexels),
		M_(GetPictureTexels),
		M_(UnloadPicture),
		M_(LoadFont),
		M_(UnloadFont),
		M_(GetTextSize),
		M_(LoadTextImage),
		M_(DrawTextImage),
		M_(DrawClippedTextImage),
		M_(UnloadTextImage),
		M_(DrawBox),
		M_(DrawLine),
		M_(DrawGrid),
		{ 0, 0 }
	};

	luaL_openlib(L, "Render", RenderFuncs, 0);
}
Exemplo n.º 6
0
void LuaSecureRandom::Register(lua_State *L)
{
	lua_newtable(L);
	int methodtable = lua_gettop(L);
	luaL_newmetatable(L, className);
	int metatable = lua_gettop(L);

	lua_pushliteral(L, "__metatable");
	lua_pushvalue(L, methodtable);
	lua_settable(L, metatable);

	lua_pushliteral(L, "__index");
	lua_pushvalue(L, methodtable);
	lua_settable(L, metatable);

	lua_pushliteral(L, "__gc");
	lua_pushcfunction(L, gc_object);
	lua_settable(L, metatable);

	lua_pop(L, 1);

	luaL_openlib(L, 0, methods, 0);
	lua_pop(L, 1);

	lua_register(L, className, create_object);
}
Exemplo n.º 7
0
int luaopen_gas(lua_State *L)
{
	auxiliar_newclass(L, "core{gas}", gas_reg);
	luaL_openlib(L, "core.gas", gaslib, 0);
	lua_pop(L, 1);
	return 1;
}
Exemplo n.º 8
0
/*
** Open math library
*/
void lua_mathlibopen (void) {
  luaL_openlib(mathlib, (sizeof(mathlib)/sizeof(mathlib[0])));
  lua_pushcfunction(math_pow);
  lua_pushnumber(0);  /* to get its tag */
  lua_settagmethod(lua_tag(lua_pop()), "pow");
  lua_pushnumber(PI); lua_setglobal("PI");
}
Exemplo n.º 9
0
static void createmeta(lua_State *L) {
  luaL_newmetatable(L, LUAIOSTRINGLIBNAME);
  lua_pushliteral(L, "__index");
  lua_pushvalue(L, -2);  /* push metatable */
  lua_rawset(L, -3);  /* metatable.__index = metatable */
  luaL_openlib(L, NULL, flib, 0);
}
Exemplo n.º 10
0
/*
 * Open our library
 */
LUALIB_API int
luaopen_sysctl_core(lua_State *L)
{

	luaL_openlib(L, "sysctl", lua_sysctl, 0);
	return (1);
}
Exemplo n.º 11
0
int
luaopen_sdl(lua_State* L)
{
  luaL_openlib(L, "SDL", sdllib, 0);

  return 1;
}
Exemplo n.º 12
0
int LUA_API luaopen_lua_dll(lua_State *L) {
  static const struct luaL_Reg api[] = {
    {"smile", smile},
    {NULL, NULL},
  };
  luaL_openlib(L, "lua_dll", api, 0);
  return 1;
}
Exemplo n.º 13
0
/*
 * Opens the cltime library.
 */
LUALIB_API int
luaopen_cltime(lua_State *lua)
{

	luaL_openlib(lua, "cltime", lib, 0);

	return 1;
}
Exemplo n.º 14
0
LUALIB_API int luaopen_toluaex_core(lua_State *L)
{
  luaL_openlib(L, MYNAME, R, 0);
  lua_pushliteral(L, "version");
  lua_pushliteral(L, MYVERSION);
  lua_settable(L, -3);
  return 1;
}
Exemplo n.º 15
0
void KitsuneSwagConsole::LoadKSCLuaLib(){

	lua_sethook(L, luadiehook, LUA_MASKCOUNT, 10000);
	lua_register(L, "print", lua_putsmyprint);

	RegFunc( "Clear", lua_cls);
	RegFunc( "Exit", lua_die);
	RegFunc( "Close", lua_closesocket);
	RegFunc( "GetAll", lua_getall); 
	RegFunc( "GetInfo", lua_getinfo);
	RegFunc("Client", lua_connectclient);
	RegFunc("Server", lua_connectserver);
	RegFunc("SetVisible", lua_SetVisible);
	RegFunc("GetVisible", lua_GetVisible);
	RegFunc("Focus", lua_Focus);

	struct luaL_reg driver[] = {
		{ "Send", lua_send },
		{ "Close", lua_closesocket },
		{ "AsInt", lua_stoi },
		{ NULL, NULL },
	};

	struct luaL_reg ls_meta[] = {
		{ "__gc", ls__gc },
		{ "__tostring", ls__tostring },
		{ "__eq", ls__eq },
		{ "__lt", ls__lt },
		{ "__le", ls__le },
		//{ "__add", Foo_add },
		{ 0, 0 }
	};

	luaL_openlib(L, PROJECT_TABLENAME, driver, 0);

	luaL_newmetatable(L, PROJECT_TABLENAME);
	luaL_openlib(L, 0, ls_meta, 0);
	lua_pushliteral(L, "__index");
	lua_pushvalue(L, -3);
	lua_rawset(L, -3);
	lua_pushliteral(L, "__metatable");
	lua_pushvalue(L, -3);
	lua_rawset(L, -3);

	lua_setglobal(ASWN->L, PROJECT_TABLENAME);
}
Exemplo n.º 16
0
static void createmeta (lua_State *L) {
  luaL_newmetatable(L, FILEHANDLE);  /* create new metatable for file handles */
  /* file methods */
  lua_pushliteral(L, "__index");
  lua_pushvalue(L, -2);  /* push metatable */
  lua_rawset(L, -3);  /* metatable.__index = metatable */
  luaL_openlib(L, NULL, flib, 0);
}
Exemplo n.º 17
0
	void registerLuaBindings(lua_State *L)
	{
		int metatable, methods;

		lua_pushliteral(L, "GameEngine_Sound");         /* name of GameEngine table */
		methods   = newtable(L);           /* GameEngine methods table */
		metatable = newtable(L);           /* GameEngine metatable */
		lua_pushliteral(L, "__index");     /* add index event to metatable */
		lua_pushvalue(L, methods);
		lua_settable(L, metatable);        /* metatable.__index = methods */
		lua_pushliteral(L, "__metatable"); /* hide metatable */
		lua_pushvalue(L, methods);
		lua_settable(L, metatable);        /* metatable.__metatable = methods */
		luaL_openlib(L, 0, SoundLua::gameengine_meta_methods,  0); /* fill metatable */
		luaL_openlib(L, 0, SoundLua::gameengine_methods, 1); /* fill GameEngine methods table */
		lua_settable(L, LUA_GLOBALSINDEX); /* add GameEngine to globals */
	}
Exemplo n.º 18
0
/*
 * Open imapfilter library of PCRE related functions.
 */
LUALIB_API int
luaopen_ifre(lua_State *lua)
{

	luaL_openlib(lua, "ifre", ifrelib, 0);

	return 1;
}
Exemplo n.º 19
0
void luaB_predefine() {
	// pre-register mem error messages, to avoid loop when error arises
	luaS_newfixedstring(tableEM);
	luaS_newfixedstring(memEM);
	luaL_openlib(int_funcs, sizeof(int_funcs) / sizeof(int_funcs[0]));
	lua_pushstring(LUA_VERSION);
	lua_setglobal("_VERSION");
}
Exemplo n.º 20
0
int luaopen_luaglu(lua_State *L)
{
  luaL_openlib(L, "glu", luaglu_lib, 0);

  luagl_initconst(L, luaglu_const);

  return 1;
}
Exemplo n.º 21
0
int luaopen_telnet(lua_State *L)
{
  luaL_newmetatable(L, OBJ_NAME);

  lua_pushstring(L, "__gc");
  lua_pushcfunction(L, l_close);
  lua_settable(L, -3);

  lua_pushstring(L, "__index");
  lua_pushvalue(L, -2);  /* pushes the metatable */
  lua_settable(L, -3);  /* metatable.__index = metatable */

  luaL_openlib(L, NULL, telnet_m, 0);

  luaL_openlib(L, "telnet", telnet_f, 0);
  return 1;
}
Exemplo n.º 22
0
extern "C" LUAMODULE_API int luaopen_uuid(lua_State *L)
{
 luaL_openlib(L,MYNAME,R,0);
 lua_pushliteral(L,"version");			/** version */
 lua_pushliteral(L,MYVERSION);
 lua_settable(L,-3);
 return 1;
}
Exemplo n.º 23
0
/*-------------------------------------------------------------------------*\
* Initializes module
\*-------------------------------------------------------------------------*/
int inet_open(lua_State *L)
{
    lua_pushstring(L, "dns");
    lua_newtable(L);
    luaL_openlib(L, NULL, func, 0);
    lua_settable(L, -3);
    return 0;
}
Exemplo n.º 24
0
LUALIB_API int luaopen_testlib(lua_State *L)
{
	luaL_newmetatable(L, "RarchDB.DB");
	lua_pushstring(L, "__index");
	lua_pushvalue(L, -2);
	lua_settable(L, -3);
	luaL_openlib(L, NULL, libretrodb_mt, 0);

	luaL_newmetatable(L, "RarchDB.Cursor");
	lua_pushstring(L, "__index");
	lua_pushvalue(L, -2);
	lua_settable(L, -3);
	luaL_openlib(L, NULL, cursor_mt, 0);

	luaL_register(L, "testlib", testlib);
	return 1;
}
Exemplo n.º 25
0
LUALIB_API int luaopen_syslinux(lua_State * L)
{

    luaL_newmetatable(L, SYSLINUX_FILE);

    luaL_openlib(L, LUA_SYSLINUXLIBNAME, syslinuxlib, 0);
    return 1;
}
Exemplo n.º 26
0
/*-------------------------------------------------------------------------*\
* Initializes module
\*-------------------------------------------------------------------------*/
int timeout_open(lua_State *L) {
#if LUA_VERSION_NUM > 501 && !defined(LUA_COMPAT_MODULE)
    luaL_setfuncs(L, func, 0);
#else
    luaL_openlib(L, NULL, func, 0);
#endif
    return 0;
}
Exemplo n.º 27
0
int luaopen_fon(lua_State *L)
{
	luaL_openlib(L, "fon", func, 0);
	lua_pushstring(L, "_VERSION");
	lua_pushstring(L, FON_VERSION);
	lua_rawset(L, -3);
	return 1;
}
Exemplo n.º 28
0
Arquivo: lposix.c Projeto: ktf/apt-rpm
LUALIB_API int luaopen_posix (lua_State *L)
{
	luaL_openlib(L, MYNAME, R, 0);
	lua_pushliteral(L,"version");		/** version */
	lua_pushliteral(L,MYVERSION);
	lua_settable(L,-3);
	return 1;
}
Exemplo n.º 29
0
void luaSystem_init(lua_State *L) {
    luaL_openlib(L, "System", System_functions, 0);
    luaL_openlib(L, "ZIP", Zip_functions, 0);

#define PSP_UTILITY_CONSTANT(name)\
    lua_pushstring(L, #name);\
    lua_pushnumber(L, PSP_UTILITY_##name);\
    lua_settable(L, -3);

    lua_pushstring(L, "System");
    lua_gettable(L, LUA_GLOBALSINDEX);

    PSP_UTILITY_CONSTANT(MSGDIALOG_RESULT_UNKNOWN1);
    PSP_UTILITY_CONSTANT(MSGDIALOG_RESULT_YES);
    PSP_UTILITY_CONSTANT(MSGDIALOG_RESULT_NO);
    PSP_UTILITY_CONSTANT(MSGDIALOG_RESULT_BACK);
}
Exemplo n.º 30
0
bool 
runLua(const std::string& filename)
{
   GRLUA_DEBUG("Importing scene from " << filename);
   
   // Start a lua interpreter
   lua_State* L = lua_open();
   
   GRLUA_DEBUG("Loading base libraries");
   
   // Load some base library
   luaopen_base(L);
   luaopen_io(L);
   luaopen_string(L);
   luaopen_math(L);
   luaopen_table(L);
   
   GRLUA_DEBUG("Setting up our functions");
   
   // Set up the metatable for gr.node
   luaL_newmetatable(L, "gr.node");
   lua_pushstring(L, "__index");
   lua_pushvalue(L, -2);
   lua_settable(L, -3);
   
   // Load the gr.node methods
   luaL_openlib(L, 0, grlib_node_methods, 0);
   
   // Load the gr functions
   luaL_openlib(L, "gr", grlib_functions, 0);
   
   GRLUA_DEBUG("Parsing the scene");
   
   // Now parse the actual scene
   if (luaL_loadfile(L, filename.c_str()) || lua_pcall(L, 0, 0, 0)) {
      std::cerr << "Error loading " << filename << ": " << lua_tostring(L, -1) << std::endl;
      return false;
   }
   GRLUA_DEBUG("Closing the interpreter");
   
   // Close the interpreter, free up any resources not needed
   lua_close(L);
   
   return true;
}