Skip to content

Commit

Permalink
1.3.0 [release]
Browse files Browse the repository at this point in the history
  • Loading branch information
Y0SH1M4S73R committed Sep 3, 2022
1 parent 55fc0bb commit 0f80d29
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [1.3.0]

### Added

- Adds the `loadstring` function. It compiles a string into lua code - if the code compiles, `loadstring` will return a function that runs that code; otherwise, it returns `nil` and the error that prevented the code from compiling.

## [1.2.1]

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "auxlua"
version = "1.2.1"
version = "1.3.0"
authors = ["Y0SH1M4S73R <[email protected]>"]
edition = "2021"

Expand Down
18 changes: 18 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ fn print(lua: &Lua, args: MultiValue) -> mlua::Result<()> {
})
}

fn loadstring(state: &Lua, mut code: String) -> mlua::Result<(mlua::Value, mlua::Value)> {
if code.is_empty() {
code = String::from(" "); //mlua bug workaround
}
match state.load(&code).into_function() {
Ok(f) => Ok((mlua::Value::Function(f), mlua::Nil)),
Err(e) => Ok((mlua::Nil, mlua::Value::Error(e))),
}
}

/// Applies auxlua-specific data structures to the lua state
fn apply_state_vars(state: &Lua, id: String) -> DMResult<()> {
let globals = state.globals();
Expand Down Expand Up @@ -273,6 +283,14 @@ fn apply_state_vars(state: &Lua, id: String) -> DMResult<()> {
.raw_set("print", print)
.map_err(|e| specific_runtime!("{}", e))?;

// Set loadstring
let loadstring = state
.create_function(loadstring)
.map_err(|e| specific_runtime!("{}", e))?;
globals
.raw_set("loadstring", loadstring)
.map_err(|e| specific_runtime!("{}", e))?;

let global_metatable = state
.create_table()
.map_err(|e| specific_runtime!("{}", e))?;
Expand Down

0 comments on commit 0f80d29

Please sign in to comment.