Commit Graph

306 Commits

Author SHA1 Message Date
Roberto Ierusalimschy 59c88f846d Broadening the use of branch hints
More uses of macros 'likely'/'unlikely' (renamed to
'l_likely'/'l_unlikely'), both in range (extended to the
libraries) and in scope (extended to hooks, stack growth).
2021-02-24 11:14:44 -03:00
Roberto Ierusalimschy 754ca0060f n Windows, 'popen' accepts "[rw][bt]?" as valid modes
Added the modifiers 'b' and 't' to valid modes for 'popen' in Windows.
2020-12-03 12:09:50 -03:00
Roberto Ierusalimschy 1ecfbfa1a1 Fixed bug: invalid mode can crash 'io.popen' 2020-07-15 16:01:03 -03:00
Roberto Ierusalimschy efcf24be0c 'luaL_execresult' does not assume -1 status as error
ISO C is silent about the return of 'system'. Windows sets 'errno' in
case of errors. Linux has several different error cases, with different
return values. ISO C allows 'system' to set 'errno' even if there are no
errors. Here we assume that a status==0 is success (which is the case
on several platforms), otherwise it is an error. If there is an error
number, gives the error based on it. (The worst a spurious 'errno'
can do is to generate a bad error message.) Otherwise uses the normal
results.
2020-05-22 15:39:29 -03:00
Roberto Ierusalimschy 46c3587a6f Clearer distinction between types and tags
LUA_T* represents only types; tags (types + Variants) are represented
by LUA_V* constants.
2020-01-31 11:09:53 -03:00
Roberto Ierusalimschy b96b0b5abb Added macro 'luaL_pushfail'
The macro 'luaL_pushfail' documents all places in the standard libraries
that return nil to signal some kind of failure. It is defined as
'lua_pushnil'. The manual also got a notation (@fail) to document those
returns. The tests were changed to be agnostic regarding whether 'fail'
is 'nil' or 'false'.
2019-08-16 14:58:02 -03:00
Roberto Ierusalimschy 223bb04090 Correction in the documentation of 'io.lines'
The loop does not end on end of file, but when the iterator function
fails to read a value. (In particular, the format "a" never fails,
so a loop with 'io.lines(fname, "a")' never ends.)
2019-07-31 11:41:59 -03:00
Roberto Ierusalimschy e888976bc6 Details (typos in comments) 2019-07-05 15:03:15 -03:00
Roberto Ierusalimschy 924bed7297 Methods separated from metamethods in 'io'
In the 'io' library, changed the use of the metatable also as its
own "method table", so that metamethods cannot be accessed as if they
were methods. (For instance, 'io.stdin.__gc' does not result in
the finalizer metamethod anymore.)
2019-07-01 12:25:00 -03:00
Roberto Ierusalimschy b293ae0577 Details
- new error message for "attempt to assign to const variable"
- note in the manual about compatibility options
- comments
- small changes in 'read_line' and 'pushstr'
2019-05-28 15:46:49 -03:00
Roberto Ierusalimschy 0b63d79b36 Details
- 'luaL_setfuncs' avoids creating closures for placeholders.
- Fixed some warnings about unused values in comma expressions.
- Comments.
2019-05-13 16:20:40 -03:00
Roberto Ierusalimschy 7f6f70853c To-be-closed variable in 'for' loop separated from the state
The variable to be closed in a generic 'for' loop now is the
4th value produced in the loop initialization, instead of being
the loop state (the 2nd value produced). That allows a loop to
use a state with a '__toclose' metamethod but do not close it.
(As an example, 'f:lines()' might use the file 'f' as a state
for the loop, but it should not close the file when the loop ends.)
2018-11-07 14:42:05 -02:00
Roberto Ierusalimschy 2fc6b55dae Removed resource-related "emergency collections"
New to-be-closed variables is a better way to ensure the proper release
of resources.
2018-10-31 16:25:29 -03:00
Roberto Ierusalimschy 947a372f58 State in generic 'for' acts as a to-be-closed variable
The implicit variable 'state' in a generic 'for' is marked as a
to-be-closed variable, so that the state will be closed as soon
as the loop ends, no matter how.

Taking advantage of this new facility, the call 'io.lines(filename)'
now returns the open file as a second result. Therefore,
an iteraction like 'for l in io.lines(name)...' will close the
file even when the loop ends with a break or an error.
2018-10-31 14:54:45 -03:00
Roberto Ierusalimschy 0a9aca56ca Added a '__close' metamethod to file handles 2018-10-23 13:57:25 -03:00
Roberto Ierusalimschy 3d838f635c Added "emergency collection" to 'io.tmpfile' and 'os.tmpname'
These operations also can give errors for lack of resources, so they
also will try "emergency collections" in case of resource errors.
Because there are now two libraries with that kind of handling,
'resourcetryagain' was moved to the auxiliary library to be shared
by the libraries.
2018-07-27 15:50:53 -03:00
Roberto Ierusalimschy e885dee5ab File operations try an "emergency collection" when failing
If a file operation fails do to lack of resources (too many open
files or not enough memory), it does a full garbage collection and
tries the operation again. Lack of resources are "too many open
files" (process wise and system wise) and "not enough memory".
The code is full of '#if's because error codes are not part
of the standard ISO C.
2018-07-25 11:44:46 -03:00
Roberto Ierusalimschy 00008b8ed0 back to one format per argument 2018-03-02 15:25:00 -03:00
Roberto Ierusalimschy c67603fafb using new 'lua_newuserdatauv' instead of 'lua_newuserdata' 2018-02-21 10:48:44 -03:00
Roberto Ierusalimschy c47111bd4e 'io.read' accepts multiple formats in a single string argument 2017-11-16 14:28:36 -02:00
Roberto Ierusalimschy e4e5aa85a2 detail ('signal' -> 'sign' in comments) 2017-11-16 11:19:06 -02:00
Roberto Ierusalimschy d266d40dea error when calling close method without arguments (e.g.,
|io.stdin.close()|)
2017-02-09 12:50:05 -02:00
Roberto Ierusalimschy 9903dd52a3 Using LUAI_UAC* types more consistently on vararg calls 2016-12-20 16:37:00 -02:00
Roberto Ierusalimschy 3b91b07fd9 detail (macro 'l_checkmode' reimplemented as function) 2016-09-01 13:14:56 -03:00
Roberto Ierusalimschy f3b52a6061 'io.read("n")' accepts both a dot and the locale point as its
radix character + 'MAXRN' -> 'L_MAXLENNUM' + small detail in
'test2'
2016-05-02 11:03:19 -03:00
Roberto Ierusalimschy 71344b5cac easy the way to accept other modifiers for 'mode' in 'io.open' 2015-11-23 09:36:11 -02:00
Roberto Ierusalimschy 050e8536bb bug: 'io.lines' does not check maximum number of options 2015-07-15 11:40:28 -03:00
Roberto Ierusalimschy 5b6ac971f9 detail (comment) 2015-07-07 14:03:34 -03:00
Roberto Ierusalimschy 43cff79bf7 detail 2015-06-21 10:50:29 -03:00
Roberto Ierusalimschy 48d0674c2e more consistent use of locale radix character across Lua 2015-04-03 15:41:57 -03:00
Roberto Ierusalimschy d7d44b038d detail (use 'lua_pushliteral' to push an empty string) 2015-03-06 16:09:08 -03:00
Roberto Ierusalimschy 234fb7f695 clearer(?) code (also avoids a warning about 'c' being used
without initialization)
2015-01-02 10:50:28 -02:00
Roberto Ierusalimschy 1735c05ac7 avoid memory errors while a file is locked (when reading a line) 2014-11-21 10:17:33 -02:00
Roberto Ierusalimschy e75c0148c3 comments (references to "ANSI C" changed to "ISO C", which is the
international name
2014-11-02 17:33:33 -02:00
Roberto Ierusalimschy 28fdbcf393 added include for 'lprefix.h', for stuff that must be added before
any other header file
2014-11-02 17:19:04 -02:00
Roberto Ierusalimschy 1a69a3ecea LUA_WIN -> LUA_USE_WINDOWS 2014-10-31 13:54:06 -02:00
Roberto Ierusalimschy bdf566a8a3 `name' in comments changed to 'name' 2014-10-25 09:50:46 -02:00
Roberto Ierusalimschy 88ff582fd8 detail (using 'sizeof' instead of 'strlen' for length of a constant
string)
2014-10-22 14:55:57 -02:00
Roberto Ierusalimschy 6b12b82532 added 'l_' prefix for names that can be redefined externally 2014-10-22 09:44:20 -02:00
Roberto Ierusalimschy 0d31efb365 'lua_stringtonum' -> 'lua_stringtonumber' 2014-10-17 16:17:55 -03:00
Roberto Ierusalimschy f97c64d7bf macros 'LUA_QL'/'LUA_QL' deprecated 2014-10-17 13:28:21 -03:00
Roberto Ierusalimschy 89602bf747 'lua_strtonum' -> 'lua_stringtonum' 2014-10-15 11:27:40 -03:00
Roberto Ierusalimschy 2f4d429071 details (comments) 2014-10-03 09:54:57 -03:00
Roberto Ierusalimschy 27f7bd2e83 detail 2014-10-01 13:05:06 -03:00
Roberto Ierusalimschy 56699cd603 small change to avoid bug in some versions of the clang compiler 2014-09-26 11:09:21 -03:00
Roberto Ierusalimschy 3ccbae84d2 added some casts between integral types (to avoid warnings) 2014-07-29 13:01:00 -03:00
Roberto Ierusalimschy b9dcf9974d detail (typos in comments) 2014-06-30 16:48:08 -03:00
Roberto Ierusalimschy e9d86eddf3 if numeral overflows the reading buffer, signal it as invalid input
(resulting in nil)
2014-06-02 00:00:51 -03:00
Roberto Ierusalimschy e966e53791 no more use of 'scanf' for reading numbers 2014-05-21 12:24:21 -03:00
Roberto Ierusalimschy 1ddb251d86 using a more conventional handling of stack space in 'io_readline' 2014-05-15 12:21:06 -03:00