Skip to content

Commit

Permalink
Make argument on io.flush optional
Browse files Browse the repository at this point in the history
  • Loading branch information
edubart committed Oct 3, 2020
1 parent f736933 commit dbc37b3
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/pages/libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ This page is under construction and very incomplete.
| `global io.stdout: filestream`{:.language-nelua} | Output file used for io.write. |
| `global io.stdin: filestream`{:.language-nelua} | Input file used for io.read. |
| `io.open(filename: stringview[, mode: stringview]) : (filestream, stringview, integer)`{:.language-nelua} | Opens a file. Alias of `filestream.open`. |
| `io.flush(file: filestream): boolean`{:.language-nelua} | Flushes the `file` |
| `io.flush(): boolean`{:.language-nelua} | Flushes stdout. |
| `io.close([file])`{:.language-nelua} | Alias of `file:close`. Closes `io.stdout` if no file was given. |
| `io.input(file: [stringview, filestream, niltype]): filestream`{:.language-nelua} | Sets, opens or returns the input file. |
| `io.output(file: [stringview, filestream, niltype]): filestream`{:.language-nelua} | Sets, opens or returns the output file. |
Expand Down
10 changes: 5 additions & 5 deletions lib/allocators/gc.nelua
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,12 @@ function GC:alloc0_opt(size: usize, flags: usize, finalizer: FinalizerCallback):
return self:_alloc(ptr, size, flags, finalizer)
end

function GC:alloc(size: usize): pointer
function GC:alloc(size: usize): pointer <noinline>
check(size > 0, 'GCAllocator.alloc: size cannot be zero')
return self:alloc_opt(size, 0, nilptr)
end

function GC:alloc0(size: usize): pointer
function GC:alloc0(size: usize): pointer <noinline>
check(size > 0, 'GCAllocator.alloc0: size must be greater than 0')
return self:alloc0_opt(size, 0, nilptr)
end
Expand Down Expand Up @@ -530,19 +530,19 @@ function GC:_realloc(qtr: pointer, ptr: pointer, size: usize): pointer <inline>
return nilptr
end

function GC:realloc(ptr: pointer, size: usize, oldsize: usize): pointer
function GC:realloc(ptr: pointer, size: usize, oldsize: usize): pointer <noinline>
local qtr: pointer = allocator:realloc(ptr, size, oldsize)
if not qtr then return nilptr end
return self:_realloc(qtr, ptr, size)
end

function GC:realloc0(ptr: pointer, size: usize, oldsize: usize): pointer
function GC:realloc0(ptr: pointer, size: usize, oldsize: usize): pointer <noinline>
local qtr: pointer = allocator:realloc0(ptr, size, oldsize)
if not qtr then return nilptr end
return self:_realloc(qtr, ptr, size)
end

function GC:dealloc(ptr: pointer)
function GC:dealloc(ptr: pointer) <noinline>
local p: *GCItem = self:_get_ptr(ptr)
if p then
if p.finalizer then
Expand Down
4 changes: 2 additions & 2 deletions lib/io.nelua
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ function io.open(filename: stringview,
return filestream.open(filename, mode)
end

function io.flush(file: filestream): boolean
return file:flush()
function io.flush(): boolean
return io.stdout:flush()
end

function io.close(file: #[concept(function(x)
Expand Down
2 changes: 1 addition & 1 deletion nelua/utils/errorer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ local function get_pretty_source_pos_errmsg(src, lineno, colno, errmsg, errname,
local errmsgcolor = colreset..colbright

-- generate the error message
return string.format("%s:%d:%d: %s: %s\n%s\n%s%s",
return string.format("%s:%d:%d: %s: %s\n%s\n%s%s\n",
srcname..colbright, lineno, colno, errcolor..errname, errmsgcolor..errmsg..colreset,
line, linehelper, errtraceback)
end
Expand Down
3 changes: 1 addition & 2 deletions tests/io_test.nelua
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ do -- basic io.open/io.isopen/io.close

file = io.open('LICENSE', 'r')
assert(io.isopen(file) == true)
assert(io.flush(file) == true)
assert(io.flush(file) == true)
assert(io.close(file) == true)
assert(not io.isopen(file))
end
Expand Down Expand Up @@ -163,6 +161,7 @@ do -- io.output/io.write
assert(io.stdout ~= stdout)
assert(io.write('test1') == true)
assert(io.stdout:write('!!\n') == true)
assert(io.flush() == true)
assert(io.output(stdout) == stdout)
assert(io.stdout == stdout)
assert(io.stdout:isopen())
Expand Down

0 comments on commit dbc37b3

Please sign in to comment.