Ejemplo n.º 1
0
int persist_l(lua_State *L) {
	/* perms? rootobj? ...? */
	WriterInfo wi;

	wi.buf = NULL;
	wi.buflen = 0;

	lua_settop(L, 2);
	/* perms? rootobj? */
	luaL_checktype(L, 1, LUA_TTABLE);
	/* perms rootobj? */
	luaL_checktype(L, 1, LUA_TTABLE);
	/* perms rootobj */

	pluto_persist(L, bufwriter, &wi);

	lua_settop(L, 0);
	/* (empty) */
	lua_pushlstring(L, wi.buf, wi.buflen);
	/* str */
	luaM_freearray(L, wi.buf, wi.buflen, char);
	return 1;
}
Ejemplo n.º 2
0
bool LuaScriptEngine::persist(OutputPersistenceBlock &writer) {
	// Empty the Lua stack. pluto_persist() xepects that the stack is empty except for its parameters
	lua_settop(_state, 0);

	// Garbage Collection erzwingen.
	lua_gc(_state, LUA_GCCOLLECT, 0);

	// Permanents-Table is set on the stack
	// pluto_persist expects these two items on the Lua stack
	pushPermanentsTable(_state, PTT_PERSIST);
	lua_getglobal(_state, "_G");

	// Lua persists and stores the data in a Common::Array
	Common::Array<byte> chunkData;
	pluto_persist(_state, chunkwriter, &chunkData);

	// Persistenzdaten in den Writer schreiben.
	writer.writeByteArray(chunkData);

	// Die beiden Tabellen vom Stack nehmen.
	lua_pop(_state, 2);

	return true;
}