lune_std_regex/
lib.rs

1#![allow(clippy::cargo_common_metadata)]
2
3use mlua::prelude::*;
4
5use lune_utils::TableBuilder;
6
7mod captures;
8mod matches;
9mod regex;
10
11use self::regex::LuaRegex;
12
13const TYPEDEFS: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/types.d.luau"));
14
15/**
16    Returns a string containing type definitions for the `regex` standard library.
17*/
18#[must_use]
19pub fn typedefs() -> String {
20    TYPEDEFS.to_string()
21}
22
23/**
24    Creates the `regex` standard library module.
25
26    # Errors
27
28    Errors when out of memory.
29*/
30pub fn module(lua: Lua) -> LuaResult<LuaTable> {
31    TableBuilder::new(lua)?
32        .with_function("new", new_regex)?
33        .build_readonly()
34}
35
36fn new_regex(_: &Lua, pattern: String) -> LuaResult<LuaRegex> {
37    LuaRegex::new(pattern)
38}