Skip to main content

FileOpenHook

Type Alias FileOpenHook 

Source
pub type FileOpenHook = fn(filename: &[u8], mode: &[u8]) -> Result<Box<dyn LuaFileHandle>, LuaError>;
Expand description

Function-pointer signature for opening a file handle, installed on GlobalState::file_open_hook by the embedder.

std::fs is banned outside lua-cli, so lua-stdlib’s io library reaches the filesystem via this hook. None causes io.open and io.output(name) to return a “file system not available” error, which is appropriate for sandboxed embeddings.

mode is a Lua fopen-style mode string (e.g. b"r", b"w", b"a", b"r+", etc.). The hook must honour at least r, w, and a.