Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GitHub workflows instead of travis #215

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Merge branch 'master' into github-ci
  • Loading branch information
tomaka committed Apr 16, 2024
commit b3d46d15260103ddd62056c38182ec680bdd6d1e
57 changes: 0 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,63 +234,6 @@ fn main() {
}
```

### Creating a Lua module

**Note: OBSOLETE ; this is still some pre-Rust-1.0 stuff**

This library also includes a second library named `rust-hl-lua-module` which allows you to create Lua modules in Rust.

To use it, add this to `Cargo.toml`:

```toml
[dependencies.rust-hl-lua-modules]
git = "https://github.com/tomaka/hlua"
```

Then you can use it like this:

```rust
#![feature(phase)]
#[!plugin(rust-hl-lua-modules)]

#[export_lua_module]
pub mod mylib { // <-- must be the name of the Lua module
static PI: f32 = 3.141592;

fn function1(a: int, b: int) -> int {
a + b
}

fn function2(a: int) -> int {
a + 5
}

#[lua_module_init]
fn init() {
println!("module initialized!")
}
}
```

This module will then be usable by Lua:

```lua
> mylib = require("mylib")
module initialized!
> return mylib.function1(2, 4)
6
> return mylib.PI
3.141592
```

Two syntax extensions are defined:
- `#[export_lua_module]`: Must be put in front of a module. The name of the module must be the same as the name of your Lua module.
- `#[lua_module_init]`: Can be put in front of a function inside the module. This function will be executed when the module is loaded.

**Restrictions**:
- `fail!()` will crash the program.
- If you spawn tasks, they will have to end before the hand is given back to lua.

### Contributing

Contributions are welcome!
2 changes: 1 addition & 1 deletion hlua/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hlua"
version = "0.4.1"
version = "0.4.2"
authors = [ "pierre.krieger1708@gmail.com" ]
description = "Zero-cost high-level wrapper for Lua"
keywords = ["lua"]
Expand Down
14 changes: 9 additions & 5 deletions hlua/examples/sound-api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ fn main() {
sound_namespace.set("new", hlua::function0(|| Sound::new()));
}

lua.execute::<()>(r#"
lua.execute::<()>(
r#"
s = Sound.new();
s:play();

Expand All @@ -23,8 +24,9 @@ fn main() {
s:stop();
print("is the sound playing:", s:is_playing());

"#)
.unwrap();
"#,
)
.unwrap();
}

// this `Sound` struct is the object that we will use to demonstrate hlua
Expand All @@ -43,8 +45,10 @@ implement_lua_push!(Sound, |mut metatable| {

index.set("stop", hlua::function1(|snd: &mut Sound| snd.stop()));

index.set("is_playing",
hlua::function1(|snd: &Sound| snd.is_playing()));
index.set(
"is_playing",
hlua::function1(|snd: &Sound| snd.is_playing()),
);
});

// this macro implements the require traits so that we can *read* the object back
Expand Down
Loading
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.