pub struct Htl { /* private fields */ }Expand description
An mlua state with the Teal compiler loaded.
Implementations§
Source§impl Htl
impl Htl
Sourcepub fn apply_project(&self, p: &Project) -> Result<()>
pub fn apply_project(&self, p: &Project) -> Result<()>
Make the project’s vendored deps visible to the Teal checker and to the
prelude’s strict searcher (htl run / htl test without a Registry).
Source§impl Htl
impl Htl
Sourcepub fn install_test_lib(&self) -> Result<()>
pub fn install_test_lib(&self) -> Result<()>
Make require("htl.test") work at runtime and its types visible to the checker.
Source§impl Htl
impl Htl
Sourcepub fn apply_config(&self, root: &Path, cfg: &HtlConfig) -> Result<()>
pub fn apply_config(&self, root: &Path, cfg: &HtlConfig) -> Result<()>
Make an htl.toml project’s dirs visible to the checker: root, root/src and
[check] paths. root is the directory holding htl.toml.
Sourcepub fn contract_check(
&self,
file: &Path,
modname: &str,
type_path: &str,
require_fields: bool,
) -> Result<ContractResult>
pub fn contract_check( &self, file: &Path, modname: &str, type_path: &str, require_fields: bool, ) -> Result<ContractResult>
Static form of TealResolver::expect_type / require_fields for one module file:
modname is what a require would say (its stem), type_path is "defs.Mod".
Source§impl Htl
impl Htl
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
New state. Uses Lua::unsafe_new so stripped bytecode bundles can be loaded.
Sourcepub fn with_checker(checker: &Htl) -> Result<Self>
pub fn with_checker(checker: &Htl) -> Result<Self>
A fresh program state that borrows checker’s compiler instead of loading its
own: modules checker has already type-checked and generated are served from
its store, so a run of many programs (the test runner: one state per file)
checks each module once. The program state itself is as isolated as
new: nothing but the checker is shared. The checker starts a new
program env for this state (module-name resolution is per program).
Sourcepub fn search_path(&self) -> Result<String>
pub fn search_path(&self) -> Result<String>
The checker’s package.path (what require inside .tl resolves through).
Sourcepub fn set_search_path(&self, path: &str) -> Result<()>
pub fn set_search_path(&self, path: &str) -> Result<()>
Restore a checker package.path taken with search_path.
Sourcepub fn from_lua(lua: Lua) -> Result<Self>
pub fn from_lua(lua: Lua) -> Result<Self>
Attach the Teal compiler to an existing Lua state (the host’s own Lua).
pub fn lua(&self) -> &Lua
Sourcepub fn gen_lua(&self, file: &Path) -> Result<(Option<String>, CheckInfo)>
pub fn gen_lua(&self, file: &Path) -> Result<(Option<String>, CheckInfo)>
Type-check and generate Lua source. None code means errors (see CheckInfo).
Sourcepub fn configure_lints(&self, spec: &str) -> Result<()>
pub fn configure_lints(&self, spec: &str) -> Result<()>
Configure lint rules: "+no-any,-shadow-local" on top of the defaults.
Sourcepub fn lint_rules(&self) -> Result<Vec<String>>
pub fn lint_rules(&self) -> Result<Vec<String>>
Names of all lint rules (enabled or not).
Sourcepub fn format_file(&self, file: &Path, indent: usize) -> Result<String>
pub fn format_file(&self, file: &Path, indent: usize) -> Result<String>
Format a .tl file (whitespace-only formatter). Returns the formatted text.
Sourcepub fn reset_search_path(&self) -> Result<()>
pub fn reset_search_path(&self) -> Result<()>
Drop Lua’s default search path (cwd-relative ./?.lua etc.) so only directories
passed to add_path are consulted by the checker and require.
Sourcepub fn add_layout_paths(&self, file: &Path) -> Result<()>
pub fn add_layout_paths(&self, file: &Path) -> Result<()>
Search paths implied by where file sits in the scaffold layout: its own
directory, and for a file under tests/ also the project root and <root>/src
(the test runner’s rule, so htl check tests sees what htl test sees).
Sourcepub fn add_path(&self, dir: &Path) -> Result<()>
pub fn add_path(&self, dir: &Path) -> Result<()>
Prepend dir/?.tl;dir/?/init.tl to package.path (Teal resolves requires through it).
Sourcepub fn install_searcher(&self) -> Result<()>
pub fn install_searcher(&self) -> Result<()>
Install the strict .tl searcher: require of a .tl with type errors fails.
Sourcepub fn preload(&self, name: &str, lua_src: &str) -> Result<()>
pub fn preload(&self, name: &str, lua_src: &str) -> Result<()>
Register generated Lua source under a module name (package.preload).
Sourcepub fn preload_bytes(&self, name: &str, bytecode: &[u8]) -> Result<()>
pub fn preload_bytes(&self, name: &str, bytecode: &[u8]) -> Result<()>
Register stripped bytecode (e.g. from include_tl_bytes!) under a module name.
Sourcepub fn exec_bytes(
&self,
bytecode: &[u8],
chunk_name: &str,
args: &[String],
) -> Result<()>
pub fn exec_bytes( &self, bytecode: &[u8], chunk_name: &str, args: &[String], ) -> Result<()>
Execute stripped bytecode with ... = args.
Sourcepub fn preload_value(&self, name: &str, value: impl IntoLua) -> Result<()>
pub fn preload_value(&self, name: &str, value: impl IntoLua) -> Result<()>
Register a ready-made value (typically a Rust-built table) as a module.
Sourcepub fn set_arg(&self, script: &str, args: &[String]) -> Result<()>
pub fn set_arg(&self, script: &str, args: &[String]) -> Result<()>
Set the global arg table like the lua CLI does.
Sourcepub fn exec(
&self,
lua_src: &str,
chunk_name: &str,
args: &[String],
) -> Result<()>
pub fn exec( &self, lua_src: &str, chunk_name: &str, args: &[String], ) -> Result<()>
Execute Lua source with ... = args.
Sourcepub fn run_file(&self, file: &Path, args: &[String]) -> Result<CheckInfo>
pub fn run_file(&self, file: &Path, args: &[String]) -> Result<CheckInfo>
Check + gen + run a .tl script. If the check fails the script is not run and the
returned CheckInfo carries the errors. Runtime errors come back as Err.
Sourcepub fn compile(&self, name: &str, lua_src: &str) -> Result<Vec<u8>>
pub fn compile(&self, name: &str, lua_src: &str) -> Result<Vec<u8>>
Compile Lua source to stripped bytecode (Lua 5.4 format of this build).
Sourcepub fn compile_with(
&self,
name: &str,
lua_src: &str,
strip: bool,
) -> Result<Vec<u8>>
pub fn compile_with( &self, name: &str, lua_src: &str, strip: bool, ) -> Result<Vec<u8>>
Compile to bytecode; strip drops debug info (line numbers, local and upvalue
names, and the chunk name: tracebacks then show the name given at load).
Sourcepub fn fingerprint(&self) -> Result<Vec<u8>>
pub fn fingerprint(&self) -> Result<Vec<u8>>
The Lua bytecode header this state produces (signature, version, format,
LUAC_DATA, sizes of Instruction / Integer / Number, endianness probes): what
another state must match to load this state’s bytecode. Lua’s own version byte
is the same for every 5.4.x, so bundles carry this instead.
Sourcepub fn lua_requires(&self, src: &str, file: &Path) -> Result<Vec<RequireSite>>
pub fn lua_requires(&self, src: &str, file: &Path) -> Result<Vec<RequireSite>>
Literal requires of a plain Lua source, resolved through the checker’s path.
Sourcepub fn resolve_module(
&self,
name: &str,
) -> Result<(Option<PathBuf>, Option<PathBuf>)>
pub fn resolve_module( &self, name: &str, ) -> Result<(Option<PathBuf>, Option<PathBuf>)>
Where require(name) resolves for the checker (.tl, .d.tl or .lua), and
where a plain .lua implementation sits on the path (a .d.tl may only be
typing it). Either may be None.
Sourcepub fn install_bundle(&self, b: &Bundle) -> Result<()>
pub fn install_bundle(&self, b: &Bundle) -> Result<()>
Install a searcher serving modules from a bundle.
Auto Trait Implementations§
impl !Freeze for Htl
impl !RefUnwindSafe for Htl
impl !Send for Htl
impl !Sync for Htl
impl !UnwindSafe for Htl
impl Unpin for Htl
impl UnsafeUnpin for Htl
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more