Roberto Ierusalimschy
2d3f095448
Avoid using large buffers in 'string.format'
The result of "string.format("%.99f", -1e308) is 410 characters long,
but all other formats have much smaller limits (at most 99 plus a fex
extras). This commit avoids 'string.format' asking for a buffer
~400 chars large when ~100 will do.
6 years ago
Roberto Ierusalimschy
b0810c51c3
Small optimizations in 'string.gsub'
Avoid creating extra strings when possible:
- avoid creating new resulting string when subject was not modified
(instead, return the subject itself);
- avoid creating strings representing the captured substrings when
handling replacements like '%1' (instead, add the substring directly
to the buffer).
6 years ago
Roberto Ierusalimschy
dfebe439db
New conversion specifier '%p' for 'string.format'
The call 'string.format("%p", val)' gives a Lua equivalent to the
C API function 'lua_topointer'.
6 years ago
Roberto Ierusalimschy
cf71a5ddc7
Details
Several small improvements (code style, warnings, comments, more tests),
in particular:
- 'lua_topointer' extended to handle strings
- raises an error in 'string.format("%10q")' ('%q' with modifiers)
- in the manual for 'string.format', the term "option" replaced by
"conversion specifier" (the term used by the C standard)
6 years ago
Roberto Ierusalimschy
264659bd53
Optional 'init' argument to 'string.gmatch'
The function 'string.gmatch' now has an optional 'init' argument,
similar to 'string.find' and 'string.match'. Moreover, there was
some reorganization in the manipulation of indices in the string
library.
This commit also includes small janitorial work in the manual
and in comments in the interpreter loop.
6 years ago
Roberto Ierusalimschy
da37ac9c78
Detail
Slightly better error message for invalid conversions in 'string.format'.
6 years ago
Roberto Ierusalimschy
46beca5bed
Better error messages for some polymorphic functions
New auxiliary functions/macros 'luaL_argexpected'/'luaL_typeerror'
ease the creation of error messages such as
bad argument #2 to 'setmetatable' (nil or table expected, got boolean)
(The novelty being the "got boolean" part...)
6 years ago
Roberto Ierusalimschy
f99509581e
Removed extra information from RCS keyword strings
Version numbers and dates (mostly wrong) from RCS keyword strings
removed from all source files; only the file name are kept.
6 years ago
Roberto Ierusalimschy
b2d4d06428
avoid possible overflows when checking sizes in 'string.unpack'
7 years ago
Roberto Ierusalimschy
b03dddf9e4
removed coercion string->number in bitwise operations
(can be done with a Lua module)
7 years ago
Roberto Ierusalimschy
c67603fafb
using new 'lua_newuserdatauv' instead of 'lua_newuserdata'
7 years ago
Roberto Ierusalimschy
599f1742c6
detail (typo in comments)
7 years ago
Roberto Ierusalimschy
e4e5aa85a2
detail ('signal' -> 'sign' in comments)
7 years ago
Roberto Ierusalimschy
26679ea35b
new function 'luaV_flttointeger' to convert floats to integers (without
string coercions) + string operands to bitwise operations handled
by string metamethods
7 years ago
Roberto Ierusalimschy
4dff277255
coercion string->number in arithmetic operations moved to string
library
7 years ago
Roberto Ierusalimschy
01c96ad12e
handling of inf, -inf, and NaN by string.format'%q'
8 years ago
Roberto Ierusalimschy
1a1b2f3d7f
added 'return' to calls to 'luaL_error' (to signal to the compiler
that the function cannot continue past that call)
8 years ago
Roberto Ierusalimschy
2a235312f0
detail (removing spaces at end of lines)
8 years ago
Roberto Ierusalimschy
9903dd52a3
Using LUAI_UAC* types more consistently on vararg calls
8 years ago
Roberto Ierusalimschy
09c9fa36ea
small corrections for C++ compliance
8 years ago
Roberto Ierusalimschy
707b0ba6e2
'string.format("%q")' writes 'math.mininteger' in hexa, to ensure
it is read back as an integer
9 years ago
Roberto Ierusalimschy
4d5ab9baa6
'string.pack("cn")' does not accept strings longer than 'n'
9 years ago
Roberto Ierusalimschy
fbd8614bdb
comment (FALLTHROUGH)
9 years ago
Roberto Ierusalimschy
22093f9c6e
'string.format("%q", number)' ensures a dot as decimal point
9 years ago
Roberto Ierusalimschy
57cdb60429
no more time limits to pattern matching (at least for now)
9 years ago
Roberto Ierusalimschy
89c09c8e40
match time limit defined by variable 'string.pattlimit'
9 years ago
Roberto Ierusalimschy
e8e39a277f
'string.format"%q"' now works for all basic types (nil, boolean,
numbers, and strings)
9 years ago
Roberto Ierusalimschy
fff7d42a69
LUA_PACKPADBYTE -> LUAL_PACKPADBYTE (it is an internal library
name, not something to be usually configured)
9 years ago
Roberto Ierusalimschy
783aa8a9da
new way to avoid infinite loops in empty matches: "Python rule"
("Empty matches for the pattern are replaced only when not
adjacent to a previous match")
9 years ago
Roberto Ierusalimschy
e747491b96
comments
9 years ago
Roberto Ierusalimschy
acff3ad88d
bug: 'gmatch' iterator fails when called from a coroutine different
from the one that created it
9 years ago
Roberto Ierusalimschy
c3e9b14d24
'\0' is a control character, no need to check it explicitly
9 years ago
Roberto Ierusalimschy
c25d59a6bd
format "%s" in 'string.format' accepts embedded zeros when it
has no modifiers
9 years ago
Roberto Ierusalimschy
3feb702df8
ensure argument to 'string.format("%s")' does not contain zeros
9 years ago
Roberto Ierusalimschy
789e423b32
corrected comparisons of signed (int) with unsigned (size_t)
9 years ago
Roberto Ierusalimschy
cc3a42b190
option 'c' in 'string.pack' accepts any string size (truncating
if larger and padding if smaller)
9 years ago
Roberto Ierusalimschy
880df57e52
detail (removed unreacheable 'break')
9 years ago
Roberto Ierusalimschy
10fffcd80a
'gmatch' keeps its state in a userdata (keeping the same 'MatchState'
across calls)
9 years ago
Roberto Ierusalimschy
8264dbc2bb
implemented counter to abort non-linear behavior in pattern matching
9 years ago
Roberto Ierusalimschy
5273477cb9
in 'lua_number2strx', use the call to 'l_sprintf' to add exponent
to result directly
9 years ago
Roberto Ierusalimschy
5aabb7a891
buffer size changed from size_t to int (it is always small) +
comments + assert that printf result fits in given buffer
10 years ago
Roberto Ierusalimschy
19eb6ae580
using 'snprintf' in C99 (both for documentation of buffer sizes
and some complains from tools)
10 years ago
Roberto Ierusalimschy
99391e24ea
new configuration macro 'l_mathlim' (simplifies some dependencies
on float type)
10 years ago
Roberto Ierusalimschy
48d0674c2e
more consistent use of locale radix character across Lua
10 years ago
Roberto Ierusalimschy
e723c75c02
details (avoid 'lint' warnings)
10 years ago
Roberto Ierusalimschy
2a57d2346e
detail
10 years ago
Roberto Ierusalimschy
5e8c162b6c
detail
10 years ago
Roberto Ierusalimschy
b7dfd18612
make buffer for format specification a little larger (length modifier
can be larger than 2, e.g. "I64")
10 years ago
Roberto Ierusalimschy
8efcd411fe
own implementation for 'string.format("%a")' for C89 platforms
10 years ago
Roberto Ierusalimschy
3509914916
BUG (when compiled with long double): buffer overflow when formatting
string.format("%.99f", 1e4930)
10 years ago