int luaL_newbuffer (int size) { int old = L->Mbuffbase-L->Mbuffer; openspace(size); L->Mbuffbase = L->Mbuffer+L->Mbuffnext; return old; }
static void str_format (void) { int arg = 1; char *strfrmt = luaL_check_string(arg++); luaI_emptybuff(); /* initialize */ while (*strfrmt) { if (*strfrmt != '%') luaI_addchar(*strfrmt++); else if (*++strfrmt == '%') luaI_addchar(*strfrmt++); /* %% */ else { /* format item */ char form[MAX_FORMAT]; /* store the format ('%...') */ char *buff; char *initf = strfrmt-1; /* -1 to include % */ strfrmt = match(strfrmt, "[-+ #]*(%d*)%.?(%d*)", 0); if (capture[0].len > 3 || capture[1].len > 3) /* < 1000? */ lua_error("invalid format (width or precision too long)"); strncpy(form, initf, strfrmt-initf+1); /* +1 to include convertion */ form[strfrmt-initf+1] = 0; buff = openspace(1000); /* to store the formated value */ switch (*strfrmt++) { case 'q': luaI_addquoted(luaL_check_string(arg++)); continue; case 's': { char *s = luaL_check_string(arg++); buff = openspace(strlen(s)); sprintf(buff, form, s); break; } case 'c': case 'd': case 'i': case 'o': case 'u': case 'x': case 'X': sprintf(buff, form, (int)luaL_check_number(arg++)); break; case 'e': case 'E': case 'f': case 'g': sprintf(buff, form, luaL_check_number(arg++)); break; default: /* also treat cases 'pnLlh' */ lua_error("invalid format option in function `format'"); } lbuffer.size += strlen(buff); } } lua_pushstring(luaI_addchar(0)); /* push the result */ }
static void push_captures (void) { int i; for (i=0; i<num_captures; i++) { int l = capture[i].len; char *buff = openspace(l+1); if (l == -1) lua_error("unfinished capture"); strncpy(buff, capture[i].init, l); buff[l] = 0; lua_pushstring(buff); } }
void luaL_addchar (int c) { openspace(BUFF_STEP); L->Mbuffer[L->Mbuffnext++] = c; }
char *luaL_openspace (int size) { openspace(size); return L->Mbuffer+L->Mbuffnext; }
void luaL_addchar (int c) { openspace(1); L->Mbuffer[L->Mbuffnext++] = (char)c; }
static void addnchar (char *s, int n) { char *b = openspace(n); strncpy(b, s, n); lbuffer.size += n; }
int32 luaL_newbuffer(int32 size) { int32 old = Mbuffbase - Mbuffer; openspace(size); Mbuffbase = Mbuffer + Mbuffnext; return old; }
void luaL_addchar(int32 c) { openspace(BUFF_STEP); Mbuffer[Mbuffnext++] = c; }
char *luaL_openspace(int32 size) { openspace(size); return Mbuffer + Mbuffnext; }