Exemplo n.º 1
0
LUALIB_API void (luaL_register_light) (lua_State *L, const char *libname,
                                const luaL_Reg *l) {
#if LUA_OPTIMIZE_MEMORY > 0                              
  luaI_openlib(L, libname, l, 0, LUA_USELIGHTFUNCTIONS);
#else
  luaI_openlib(L, libname, l, 0, LUA_USECCLOSURES);
#endif  
}
Exemplo n.º 2
0
/// @brief Binds the class library to the Lua scripting system
void luaopen_class (lua_State * L)
{
	assert(L != 0);

	// Class data table.
	lua_createtable(L, eDI_N, 0);	// {}

	// Create class definition storage, userdata table storage, and the new instance stack.
	int indices[] = { eDefs, eNewI, eUDTables };

	for (int index = 0; index < sizeof(indices) / sizeof(int); ++index)
	{
		lua_newtable(L);// { ... }, {}
		lua_rawseti(L, -2, indices[index]);	// { ..., [index] = {} }
	}

	// Bind codes to each valid metamethod key.
	char const * metamethods[] = {
		"__index", "__newindex",
		"__eq", "__le", "__lt",
		"__add", "__div", "__mul", "__sub",
		"__mod", "__pow", "__unm",
		"__call", "__concat", "__gc", "__len"
	};

	lua_createtable(L, 0, sizeof(metamethods) / sizeof(char const *));	// { defs, newI, udTables }, {}

	for (int index = 0; index < sizeof(metamethods) / sizeof(char const *); ++index)
	{
		lua_pushinteger(L, index > 1 ? eNormal : eIndex + index);	// { defs, newI, udTables }, { ... }, code
		lua_setfield(L, -2, metamethods[index]);// { defs, newI, udTables }, { ..., metamethod = code }
	}

	lua_rawseti(L, -2, eMM);// { defs, MM, newI, udTables }

	// Create instance usage storage.
	lua_newtable(L);// { defs, MM, newI, userdata }, usage
	lua_pushvalue(L, -1);	// { defs, MM, newI, udTables }, usage, usage
	lua_pushliteral(L, "k");// { defs, MM, newI, udTables }, usage, usage, "k"
	lua_setfield(L, -2, "__mode");	// { defs, MM, newI, udTables }, usage, usage = { __mode = "k" }
	lua_setmetatable(L, -2);// { defs, MM, newI, udTables }, usage
	lua_rawseti(L, -2, eUsage);// { defs, MM, newI, udTables, usage }

	// Install the class function table.
	const luaL_reg Funcs[] = {
		{ "define", Define },
		{ "extend", Extend },
		{ "isinstance", IsInstance },
		{ "istype", IsType },
		{ "new", New },
		{ "scons", SCons },
		{ "super", Super },
		{ "type", Type },
		{ 0, 0 }
	};

	luaI_openlib(L, "class", Funcs, 1);	// _G.class
	lua_pop(L, 1);	// stack clear
}
Exemplo n.º 3
0
LUALIB_API int luaopen_filelib (lua_State *L) {
  luaI_openlib(L, "file", filelib, 0);
  luaL_newmetatable(L,"ramfile");
  luaL_openlib(L, 0, metafilelib, 0);
  lua_pushliteral(L, "__metatable");
  lua_pushvalue(L, -3);               /* dup methods table*/
  lua_rawset(L, -3);                  /* hide metatable:
                                         metatable.__metatable = methods */
  lua_pop(L, 1);                      /* drop metatable */
  lua_pop(L, 1);                       /* drop methods*/
  return 1;                           /* return methods on the stack */
}
Exemplo n.º 4
0
/*-------------------------------------------------------------------------*\
* Initializes module
\*-------------------------------------------------------------------------*/
int tcp_open(lua_State *L)
{
    /* create classes */
    auxiliar_newclass(L, "tcp{master}", tcp);
    auxiliar_newclass(L, "tcp{client}", tcp);
    auxiliar_newclass(L, "tcp{server}", tcp);
    /* create class groups */
    auxiliar_add2group(L, "tcp{master}", "tcp{any}");
    auxiliar_add2group(L, "tcp{client}", "tcp{any}");
    auxiliar_add2group(L, "tcp{server}", "tcp{any}");
    /* define library functions */
    luaI_openlib(L, NULL, func, 0); 
    return 0;
}
Exemplo n.º 5
0
LUALIB_API void (luaL_register) (lua_State *L, const char *libname,
                                const luaL_Reg *l) {
  luaI_openlib(L, libname, l, 0);
}
Exemplo n.º 6
0
/*
** Open math library
*/
void mathlib_open (void)
{
  luaI_openlib(mathlib, (sizeof(mathlib)/sizeof(mathlib[0])));
  old_pow = lua_refobject(lua_setfallback("arith", math_pow), 1);
}
Exemplo n.º 7
0
/*-------------------------------------------------------------------------*\
* Initializes module
\*-------------------------------------------------------------------------*/
int select_open(lua_State *L) {
    luaI_openlib(L, NULL, func, 0);
    return 0;
}
Exemplo n.º 8
0
/*
** Open string library
*/
void strlib_open (void)
{
  luaI_openlib(strlib, (sizeof(strlib)/sizeof(strlib[0])));
}
Exemplo n.º 9
0
void luag_init(lua_State *L)
{
 luaI_openlib(L, "g", glib, 0);
}
Exemplo n.º 10
0
static inline void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup) {
  luaI_openlib(L, NULL, l, nup);
}