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
67
68
69
70
71
72
73
74
//! Minimal file-handle abstraction shared between `lua-vm` (hook type) and
//! `lua-stdlib` (io library).
//!
//! `std::fs` is banned in `lua-stdlib` by PORTING.md §1. The concrete
//! implementation (backed by `std::fs::File`) lives in `lua-cli` and is
//! installed on [`lua_vm::state::GlobalState`] via the `FileOpenHook` /
//! `FileRemoveHook` / `FileRenameHook` function pointers. Those hooks return
//! `std::io::Result` (not `LuaError`): only `std::io::Error` carries
//! `raw_os_error()`, and `io.open`/`os.remove`/`os.rename` must report the real
//! errno as their third return value the way C's `luaL_fileresult` does — a
//! `LuaError` return would drop it (#301). This trait is the shared seam that
//! lets `lua-stdlib` program against file handles without importing `std::fs`.
//!
//! On the `wasm32-unknown-unknown` host boundary there is no `io::Error` to pass
//! by value, so the `open_file` host import encodes the outcome in its `i32`
//! return: `>= 0` is a live handle id, `-1` is failure with no errno available
//! (mapped to a `raw_os_error`-less error → a 2-value `(nil, msg)` result), and
//! `<= -2` encodes `errno = -id` (mapped via `io::Error::from_raw_os_error`).
//! See `lua-wasm`'s `imported_file_open` and the JS host's `openFile`.
//!
//! ## Trait design
//! The trait mirrors the subset of `LuaFileOps` (defined in `lua-stdlib`) that
//! is required to run the built-in io library at the level needed for
//! `attrib.lua`-class tests: sequential write, byte-by-byte read, flush, and
//! seek. `LuaFileOps` in `lua-stdlib` extends this trait so that a single
//! concrete type (the `FsFile` in `lua-cli`) satisfies both.
use ;
/// Capabilities required by the io library from an OS file handle.
///
/// Designed to be object-safe (`Box<dyn LuaFileHandle>`). Implementations
/// backed by `std::fs::File` live in `lua-cli`; implementations for the
/// standard streams live in `lua-stdlib/src/io_lib.rs`.