Ejemplo n.º 1
0
void GLua_Define_Sys(lua_State *L) {
	STACKGUARD_INIT(L)

	luaL_register(L, "sys", sys_f);
	lua_pop(L,1);

	STACKGUARD_CHECK(L)
}
Ejemplo n.º 2
0
void GLua_Define_File(lua_State *L) {
	STACKGUARD_INIT(L)

	luaL_register(L, "file", file_f);
	lua_pop(L,1);

	STACKGUARD_CHECK(L)
}
Ejemplo n.º 3
0
void GLua_Define_JSON( lua_State *L )
{
	STACKGUARD_INIT(L)

	luaL_register(L, "json", json_f);
	lua_pop(L,1);

	STACKGUARD_CHECK(L)
}
Ejemplo n.º 4
0
void GLua_RegisterProperties(lua_State *L, const GLua_Prop *props, int nup)
{
	STACKGUARD_INIT(L)

	// This assumes the (meta)table to assign the properties to is on top of the stack
	// This creates 2 subtables: __propget and __propset, each of which contain a table
	//  of methods and their associated functions. If no function is linked to it, it's set to 0.
	lua_newtable(L); // __propget
	lua_newtable(L); // __propset

	/* Stack layout:
	   [value]		   (-1)
	   <__propset>	-1 (-2)
	   <__propget>	-2 (-3)
	   <nups>		-3 (-4)
	   <table>		-3+nups (-4+nups)
	*/


	for (; props->prop; props++) {
		int i;
		if (props->setfunc) {
			for (i=0; i<nup; i++)  /* copy upvalues to the top */
				lua_pushvalue(L, -(nup+2));
			lua_pushcclosure(L, props->setfunc, nup);
			lua_setfield(L, -2, props->prop);
		} else {
			lua_pushnumber(L, 0);	// 'Not Available' marker
			lua_setfield(L, -2, props->prop);
		}
		if (props->getfunc) {
			for (i=0; i<nup; i++)  /* copy upvalues to the top */
				lua_pushvalue(L, -(nup+2));
			lua_pushcclosure(L, props->getfunc, nup);
			lua_setfield(L, -3, props->prop);
		} else {
			lua_pushnumber(L, 0);	// 'Not Available' marker
			lua_setfield(L, -3, props->prop);
		}
	}
	lua_setfield(L, -(nup+3), "__propset");
	lua_setfield(L, -(nup+2), "__propget");
	// Pop upvalues
	lua_pop(L, nup);

	STACKGUARD_CHECK(L)
}
void GLua_Define_BitStream(lua_State *L) {
	STACKGUARD_INIT(L)

	luaL_register(L, "bitstream", bitstream_f);
	lua_pop(L,1);

	luaL_newmetatable(L,"BitStream");
	luaL_register(L, NULL, bitstream_m);
	
	lua_pushstring(L,"ObjID");
	lua_pushinteger(L, GO_BITSTREAM);
	lua_settable(L,-3);

	lua_pushstring(L,"ObjName");
	lua_pushstring(L,"BitStream");
	lua_settable(L,-3);

	lua_pop(L,1);

	STACKGUARD_CHECK(L)
}
Ejemplo n.º 6
0
void GLua_Define_Vector(lua_State *L) {

	STACKGUARD_INIT(L)

	lua_pushcclosure(L,GLua_Vector_Create,0);
	lua_setglobal(L,"Vector");

	luaL_newmetatable(L,"Vector");
	luaL_register(L, NULL, vector_m);

	lua_pushstring(L,"ObjID");
	lua_pushinteger(L,GO_VECTOR);
	lua_settable(L,-3);

	lua_pushstring(L,"ObjName");
	lua_pushstring(L,"Vector");
	lua_settable(L,-3);

	lua_pop(L,1);

	STACKGUARD_CHECK(L)
}
Ejemplo n.º 7
0
void GLua_LoadBaseLibs(lua_State *L) {

	STACKGUARD_INIT(L)

	luaL_openlibs(L);
	// Time to make some adjustments
	//lua_pushnil(L); lua_setglobal(L,"debug"); // Debug module = gone
	lua_pushnil(L); lua_setglobal(L,"io"); // io module = gone (we'll create our own)
	// Remove some problematic functions in os
	lua_getglobal(L,"os");
	lua_pushstring(L,"exit"); lua_pushnil(L); lua_settable(L,-3); 
	lua_pushstring(L,"execute"); lua_pushnil(L); lua_settable(L,-3);
	lua_pushstring(L,"remove"); lua_pushnil(L); lua_settable(L,-3);
	lua_pushstring(L,"rename"); lua_pushnil(L); lua_settable(L,-3);
	lua_pushstring(L,"setlocale"); lua_pushnil(L); lua_settable(L,-3);
	lua_pushstring(L,"tmpname"); lua_pushnil(L); lua_settable(L,-3);
	lua_pop(L,1);
	// Add print and include
	lua_pushcclosure(L, GLua_Print, 0); lua_setglobal(L, "print");
	lua_pushcclosure(L, GLua_Include, 0); lua_setglobal(L, "include");
	lua_pushcclosure(L, GLua_FindMetatable, 0); lua_setglobal(L, "findmetatable");
	// Log/SecurityLog Printf --eez
	lua_pushcclosure(L, GLua_LogPrint, 0); lua_setglobal(L, "log");
	lua_pushcclosure(L, GLua_SecurityLogPrint, 0); lua_setglobal(L, "securitylog");
	// Print command, without newlines
	lua_pushcclosure(L, GLua_PrintNN, 0); lua_setglobal(L, "printnn");
	// Send chat messages
	lua_pushcclosure(L, GLua_Chat, 0); lua_setglobal(L, "chatmsg");
	// Remove different ways to execute code, we only want include to be available
	lua_pushnil(L); lua_setglobal(L,"dofile"); 
	lua_pushnil(L); lua_setglobal(L,"loadfile");
	lua_pushnil(L); lua_setglobal(L,"load");
	lua_pushnil(L); lua_setglobal(L,"loadstring");

	STACKGUARD_CHECK(L)
}