ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

lbuffer.cpp

Go to the documentation of this file.
00001 /*
00002 ** Auxiliary functions for building Lua libraries
00003 ** See Copyright Notice in lua.h
00004 */
00005 
00006 #define FORBIDDEN_SYMBOL_EXCEPTION_setjmp
00007 #define FORBIDDEN_SYMBOL_EXCEPTION_longjmp
00008 
00009 #include "engines/grim/lua/lauxlib.h"
00010 #include "engines/grim/lua/lmem.h"
00011 #include "engines/grim/lua/lstate.h"
00012 
00013 namespace Grim {
00014 
00015 /*-------------------------------------------------------
00016 **  Auxiliary buffer
00017 -------------------------------------------------------*/
00018 
00019 #define BUFF_STEP   32
00020 
00021 #define openspace(size)  if (Mbuffnext + (size) > Mbuffsize) Openspace(size)
00022 
00023 static void Openspace(int32 size) {
00024     int32 base = Mbuffbase - Mbuffer;
00025     Mbuffsize *= 2;
00026     if (Mbuffnext + size > Mbuffsize)  // still not big enough?
00027         Mbuffsize = Mbuffnext + size;
00028     Mbuffer = (char *)luaM_realloc(Mbuffer, Mbuffsize);
00029     Mbuffbase = Mbuffer + base;
00030 }
00031 
00032 char *luaL_openspace(int32 size) {
00033     openspace(size);
00034     return Mbuffer + Mbuffnext;
00035 }
00036 
00037 void luaL_addchar(int32 c) {
00038     openspace(BUFF_STEP);
00039     Mbuffer[Mbuffnext++] = c;
00040 }
00041 
00042 void luaL_resetbuffer() {
00043     Mbuffnext = Mbuffbase - Mbuffer;
00044 }
00045 
00046 void luaL_addsize(int32 n) {
00047     Mbuffnext += n;
00048 }
00049 
00050 int32 luaL_newbuffer(int32 size) {
00051     int32 old = Mbuffbase - Mbuffer;
00052     openspace(size);
00053     Mbuffbase = Mbuffer + Mbuffnext;
00054     return old;
00055 }
00056 
00057 void luaL_oldbuffer(int32 old) {
00058     Mbuffnext = Mbuffbase - Mbuffer;
00059     Mbuffbase = Mbuffer + old;
00060 }
00061 
00062 char *luaL_buffer() {
00063     return Mbuffbase;
00064 }
00065 
00066 } // end of namespace Grim


Generated on Sat Mar 16 2019 05:01:41 for ResidualVM by doxygen 1.7.1
curved edge   curved edge