Skip to main content

Htl

Struct Htl 

Source
pub struct Htl { /* private fields */ }
Expand description

An mlua state with the Teal compiler loaded.

Implementations§

Source§

impl Htl

Source

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

Source

pub fn install_test_lib(&self) -> Result<()>

Make require("htl.test") work at runtime and its types visible to the checker.

Source§

impl Htl

Source

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.

Source

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

Source

pub fn new() -> Result<Self>

New state. Uses Lua::unsafe_new so stripped bytecode bundles can be loaded.

Source

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).

Source

pub fn search_path(&self) -> Result<String>

The checker’s package.path (what require inside .tl resolves through).

Source

pub fn set_search_path(&self, path: &str) -> Result<()>

Restore a checker package.path taken with search_path.

Source

pub fn from_lua(lua: Lua) -> Result<Self>

Attach the Teal compiler to an existing Lua state (the host’s own Lua).

Source

pub fn lua(&self) -> &Lua

Source

pub fn check(&self, file: &Path) -> Result<CheckInfo>

Type-check one file.

Source

pub fn gen_lua(&self, file: &Path) -> Result<(Option<String>, CheckInfo)>

Type-check and generate Lua source. None code means errors (see CheckInfo).

Source

pub fn configure_lints(&self, spec: &str) -> Result<()>

Configure lint rules: "+no-any,-shadow-local" on top of the defaults.

Source

pub fn lint_rules(&self) -> Result<Vec<String>>

Names of all lint rules (enabled or not).

Source

pub fn format_file(&self, file: &Path, indent: usize) -> Result<String>

Format a .tl file (whitespace-only formatter). Returns the formatted text.

Source

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.

Source

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).

Source

pub fn add_path(&self, dir: &Path) -> Result<()>

Prepend dir/?.tl;dir/?/init.tl to package.path (Teal resolves requires through it).

Source

pub fn install_searcher(&self) -> Result<()>

Install the strict .tl searcher: require of a .tl with type errors fails.

Source

pub fn preload(&self, name: &str, lua_src: &str) -> Result<()>

Register generated Lua source under a module name (package.preload).

Source

pub fn preload_bytes(&self, name: &str, bytecode: &[u8]) -> Result<()>

Register stripped bytecode (e.g. from include_tl_bytes!) under a module name.

Source

pub fn exec_bytes( &self, bytecode: &[u8], chunk_name: &str, args: &[String], ) -> Result<()>

Execute stripped bytecode with ... = args.

Source

pub fn preload_value(&self, name: &str, value: impl IntoLua) -> Result<()>

Register a ready-made value (typically a Rust-built table) as a module.

Source

pub fn set_arg(&self, script: &str, args: &[String]) -> Result<()>

Set the global arg table like the lua CLI does.

Source

pub fn exec( &self, lua_src: &str, chunk_name: &str, args: &[String], ) -> Result<()>

Execute Lua source with ... = args.

Source

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.

Source

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).

Source

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).

Source

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.

Source

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.

Source

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.

Source

pub fn install_bundle(&self, b: &Bundle) -> Result<()>

Install a searcher serving modules from a bundle.

Source

pub fn run_bundle(&self, b: &Bundle, args: &[String]) -> Result<()>

Install the bundle and run its entry module with ... = args.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> MaybeSend for T

Source§

impl<T> MaybeSync for T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.