File: lbuffer.cpp

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (66 lines) | stat: -rw-r--r-- 1,401 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/

#define FORBIDDEN_SYMBOL_EXCEPTION_setjmp
#define FORBIDDEN_SYMBOL_EXCEPTION_longjmp

#include "engines/grim/lua/lauxlib.h"
#include "engines/grim/lua/lmem.h"
#include "engines/grim/lua/lstate.h"

namespace Grim {

/*-------------------------------------------------------
**  Auxiliary buffer
-------------------------------------------------------*/

#define BUFF_STEP        32

#define openspace(size)  if (Mbuffnext + (size) > Mbuffsize) Openspace(size)

static void Openspace(int32 size) {
	int32 base = Mbuffbase - Mbuffer;
	Mbuffsize *= 2;
	if (Mbuffnext + size > Mbuffsize)  // still not big enough?
		Mbuffsize = Mbuffnext + size;
	Mbuffer = (char *)luaM_realloc(Mbuffer, Mbuffsize);
	Mbuffbase = Mbuffer + base;
}

char *luaL_openspace(int32 size) {
	openspace(size);
	return Mbuffer + Mbuffnext;
}

void luaL_addchar(int32 c) {
	openspace(BUFF_STEP);
	Mbuffer[Mbuffnext++] = c;
}

void luaL_resetbuffer() {
	Mbuffnext = Mbuffbase - Mbuffer;
}

void luaL_addsize(int32 n) {
	Mbuffnext += n;
}

int32 luaL_newbuffer(int32 size) {
	int32 old = Mbuffbase - Mbuffer;
	openspace(size);
	Mbuffbase = Mbuffer + Mbuffnext;
	return old;
}

void luaL_oldbuffer(int32 old) {
	Mbuffnext = Mbuffbase - Mbuffer;
	Mbuffbase = Mbuffer + old;
}

char *luaL_buffer() {
	return Mbuffbase;
}

} // end of namespace Grim