Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
Last rename, I swear
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptibell committed Feb 11, 2024
1 parent 2b75b46 commit 8e8647e
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 143 deletions.
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.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "mlua-luau-runtime"
name = "mlua-luau-scheduler"
version = "0.0.0"
edition = "2021"
license = "MPL-2.0"
repository = "https://github.com/lune-org/mlua-luau-runtime"
description = "Luau-based async runtime, using mlua and async-executor"
repository = "https://github.com/lune-org/mlua-luau-scheduler"
description = "Luau-based async scheduler, using mlua and async-executor"
readme = "README.md"
keywords = ["async", "luau", "runtime"]
keywords = ["async", "luau", "scheduler"]
categories = ["async"]

[dependencies]
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<!-- markdownlint-disable MD033 -->
<!-- markdownlint-disable MD041 -->

<h1 align="center">mlua-luau-runtime</h1>
<h1 align="center">mlua-luau-scheduler</h1>

<div align="center">
<div>
<a href="https://github.com/lune-org/mlua-luau-runtime/actions">
<img src="https://shields.io/endpoint?url=https://badges.readysetplay.io/workflow/lune-org/mlua-luau-runtime/ci.yaml" alt="CI status" />
<a href="https://github.com/lune-org/mlua-luau-scheduler/actions">
<img src="https://shields.io/endpoint?url=https://badges.readysetplay.io/workflow/lune-org/mlua-luau-scheduler/ci.yaml" alt="CI status" />
</a>
<a href="https://github.com/lune-org/mlua-luau-runtime/blob/main/LICENSE.txt">
<img src="https://img.shields.io/github/license/lune-org/mlua-luau-runtime.svg?label=License&color=informational" alt="Crate license" />
<a href="https://github.com/lune-org/mlua-luau-scheduler/blob/main/LICENSE.txt">
<img src="https://img.shields.io/github/license/lune-org/mlua-luau-scheduler.svg?label=License&color=informational" alt="Crate license" />
</a>
</div>
</div>

<br/>

An async runtime for Luau, using [`mlua`][mlua] and built on top of [`async-executor`][async-executor].
An async scheduler for Luau, using [`mlua`][mlua] and built on top of [`async-executor`][async-executor].

This crate is runtime-agnostic and is compatible with any async runtime, including [Tokio][tokio], [smol][smol], [async-std][async-std], and others. </br>
However, since many dependencies are shared with [smol][smol], depending on it over other runtimes may be preferred.
Expand All @@ -39,7 +39,7 @@ use async_io::{block_on, Timer};
use async_fs::read_to_string;

use mlua::prelude::*;
use mlua_luau_runtime::*;
use mlua_luau_scheduler::*;
```

### 2. Set up Lua environment
Expand Down Expand Up @@ -73,16 +73,16 @@ lua.globals().set(
)?;
```

### 3. Set up runtime, run threads
### 3. Set up scheduler, run threads

```rs
let rt = Runtime::new(&lua)?;
let rt = Scheduler::new(&lua)?;

// We can create multiple lua threads ...
let sleepThread = lua.load("sleep(0.1)");
let fileThread = lua.load("readFile(\"Cargo.toml\")");

// ... spawn them both onto the runtime ...
// ... spawn them both onto the scheduler ...
rt.push_thread_front(sleepThread, ());
rt.push_thread_front(fileThread, ());

Expand Down
6 changes: 3 additions & 3 deletions examples/basic_sleep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::time::{Duration, Instant};
use async_io::{block_on, Timer};

use mlua::prelude::*;
use mlua_luau_runtime::Runtime;
use mlua_luau_scheduler::Scheduler;

const MAIN_SCRIPT: &str = include_str!("./lua/basic_sleep.luau");

Expand All @@ -27,8 +27,8 @@ pub fn main() -> LuaResult<()> {
})?,
)?;

// Load the main script into a runtime
let rt = Runtime::new(&lua);
// Load the main script into a scheduler
let rt = Scheduler::new(&lua);
let main = lua.load(MAIN_SCRIPT);
rt.push_thread_front(main, ())?;

Expand Down
6 changes: 3 additions & 3 deletions examples/basic_spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use async_fs::read_to_string;
use async_io::block_on;

use mlua::prelude::*;
use mlua_luau_runtime::{LuaSpawnExt, Runtime};
use mlua_luau_scheduler::{LuaSpawnExt, Scheduler};

const MAIN_SCRIPT: &str = include_str!("./lua/basic_spawn.luau");

Expand Down Expand Up @@ -46,8 +46,8 @@ pub fn main() -> LuaResult<()> {
})?,
)?;

// Load the main script into a runtime
let rt = Runtime::new(&lua);
// Load the main script into a scheduler
let rt = Scheduler::new(&lua);
let main = lua.load(MAIN_SCRIPT);
rt.push_thread_front(main, ())?;

Expand Down
8 changes: 4 additions & 4 deletions examples/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![allow(clippy::missing_panics_doc)]

use mlua::prelude::*;
use mlua_luau_runtime::Runtime;
use mlua_luau_scheduler::Scheduler;

use async_io::block_on;

Expand All @@ -18,8 +18,8 @@ pub fn main() -> LuaResult<()> {
// Set up persistent Lua environment
let lua = Lua::new();

// Create a new runtime with custom callbacks
let rt = Runtime::new(&lua);
// Create a new scheduler with custom callbacks
let rt = Scheduler::new(&lua);
rt.set_error_callback(|e| {
println!(
"Captured error from Lua!\n{}\n{e}\n{}",
Expand All @@ -28,7 +28,7 @@ pub fn main() -> LuaResult<()> {
);
});

// Load the main script into the runtime, and keep track of the thread we spawn
// Load the main script into the scheduler, and keep track of the thread we spawn
let main = lua.load(MAIN_SCRIPT);
let id = rt.push_thread_front(main, ())?;

Expand Down
6 changes: 3 additions & 3 deletions examples/exit_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use async_io::block_on;

use mlua::prelude::*;
use mlua_luau_runtime::{Functions, Runtime};
use mlua_luau_scheduler::{Functions, Scheduler};

const MAIN_SCRIPT: &str = include_str!("./lua/exit_code.luau");

Expand All @@ -17,12 +17,12 @@ pub fn main() -> LuaResult<()> {

// Set up persistent Lua environment
let lua = Lua::new();
let rt = Runtime::new(&lua);
let rt = Scheduler::new(&lua);
let fns = Functions::new(&lua)?;

lua.globals().set("exit", fns.exit)?;

// Load the main script into the runtime
// Load the main script into the scheduler
let main = lua.load(MAIN_SCRIPT);
rt.push_thread_front(main, ())?;

Expand Down
6 changes: 3 additions & 3 deletions examples/lots_of_threads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::time::Duration;
use async_io::{block_on, Timer};

use mlua::prelude::*;
use mlua_luau_runtime::{Functions, Runtime};
use mlua_luau_scheduler::{Functions, Scheduler};

const MAIN_SCRIPT: &str = include_str!("./lua/lots_of_threads.luau");

Expand All @@ -20,7 +20,7 @@ pub fn main() -> LuaResult<()> {

// Set up persistent Lua environment
let lua = Lua::new();
let rt = Runtime::new(&lua);
let rt = Scheduler::new(&lua);
let fns = Functions::new(&lua)?;

lua.globals().set("spawn", fns.spawn)?;
Expand All @@ -34,7 +34,7 @@ pub fn main() -> LuaResult<()> {
})?,
)?;

// Load the main script into the runtime
// Load the main script into the scheduler
let main = lua.load(MAIN_SCRIPT);
rt.push_thread_front(main, ())?;

Expand Down
6 changes: 3 additions & 3 deletions examples/scheduler_ordering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::time::{Duration, Instant};
use async_io::{block_on, Timer};

use mlua::prelude::*;
use mlua_luau_runtime::{Functions, Runtime};
use mlua_luau_scheduler::{Functions, Scheduler};

const MAIN_SCRIPT: &str = include_str!("./lua/scheduler_ordering.luau");

Expand All @@ -19,7 +19,7 @@ pub fn main() -> LuaResult<()> {

// Set up persistent Lua environment
let lua = Lua::new();
let rt = Runtime::new(&lua);
let rt = Scheduler::new(&lua);
let fns = Functions::new(&lua)?;

lua.globals().set("spawn", fns.spawn)?;
Expand All @@ -34,7 +34,7 @@ pub fn main() -> LuaResult<()> {
})?,
)?;

// Load the main script into the runtime, and keep track of the thread we spawn
// Load the main script into the scheduler, and keep track of the thread we spawn
let main = lua.load(MAIN_SCRIPT);
let id = rt.push_thread_front(main, ())?;

Expand Down
6 changes: 3 additions & 3 deletions examples/tracy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use tracing_subscriber::layer::SubscriberExt;
use tracing_tracy::{client::Client as TracyClient, TracyLayer};

use mlua::prelude::*;
use mlua_luau_runtime::{Functions, Runtime};
use mlua_luau_scheduler::{Functions, Scheduler};

const MAIN_SCRIPT: &str = include_str!("./lua/lots_of_threads.luau");

Expand All @@ -35,7 +35,7 @@ pub fn main() -> LuaResult<()> {

// Set up persistent Lua environment
let lua = Lua::new();
let rt = Runtime::new(&lua);
let rt = Scheduler::new(&lua);
let fns = Functions::new(&lua)?;

lua.globals().set("spawn", fns.spawn)?;
Expand All @@ -49,7 +49,7 @@ pub fn main() -> LuaResult<()> {
})?,
)?;

// Load the main script into the runtime
// Load the main script into the scheduler
let main = lua.load(MAIN_SCRIPT);
rt.push_thread_front(main, ())?;

Expand Down
32 changes: 16 additions & 16 deletions lib/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ use crate::{
error_callback::ThreadErrorCallback,
queue::{DeferredThreadQueue, SpawnedThreadQueue},
result_map::ThreadResultMap,
runtime::Runtime,
scheduler::Scheduler,
thread_id::ThreadId,
traits::LuaRuntimeExt,
traits::LuaSchedulerExt,
util::{is_poll_pending, LuaThreadOrFunction, ThreadResult},
};

const ERR_METADATA_NOT_ATTACHED: &str = "\
Lua state does not have runtime metadata attached!\
\nThis is most likely caused by creating functions outside of a runtime.\
\nRuntime functions must always be created from within an active runtime.\
Lua state does not have scheduler metadata attached!\
\nThis is most likely caused by creating functions outside of a scheduler.\
\nScheduler functions must always be created from within an active scheduler.\
";

const EXIT_IMPL_LUA: &str = r"
Expand All @@ -39,29 +39,29 @@ end
";

/**
A collection of lua functions that may be called to interact with a [`Runtime`].
A collection of lua functions that may be called to interact with a [`Scheduler`].
*/
pub struct Functions<'lua> {
/**
Implementation of `coroutine.resume` that handles async polling properly.
Defers onto the runtime queue if the thread calls an async function.
Defers onto the scheduler queue if the thread calls an async function.
*/
pub resume: LuaFunction<'lua>,
/**
Implementation of `coroutine.wrap` that handles async polling properly.
Defers onto the runtime queue if the thread calls an async function.
Defers onto the scheduler queue if the thread calls an async function.
*/
pub wrap: LuaFunction<'lua>,
/**
Resumes a function / thread once instantly, and runs until first yield.
Spawns onto the runtime queue if not completed.
Spawns onto the scheduler queue if not completed.
*/
pub spawn: LuaFunction<'lua>,
/**
Defers a function / thread onto the runtime queue.
Defers a function / thread onto the scheduler queue.
Does not resume instantly, only adds to the queue.
*/
Expand All @@ -71,7 +71,7 @@ pub struct Functions<'lua> {
*/
pub cancel: LuaFunction<'lua>,
/**
Exits the runtime, stopping all other threads and closing the runtime.
Exits the scheduler, stopping all other threads and closing the scheduler.
Yields the calling thread to ensure that it does not continue.
*/
Expand All @@ -80,15 +80,15 @@ pub struct Functions<'lua> {

impl<'lua> Functions<'lua> {
/**
Creates a new collection of Lua functions that may be called to interact with a [`Runtime`].
Creates a new collection of Lua functions that may be called to interact with a [`Scheduler`].
# Errors
Errors when out of memory, or if default Lua globals are missing.
# Panics
Panics when the given [`Lua`] instance does not have an attached [`Runtime`].
Panics when the given [`Lua`] instance does not have an attached [`Scheduler`].
*/
pub fn new(lua: &'lua Lua) -> LuaResult<Self> {
let spawn_queue = lua
Expand Down Expand Up @@ -157,7 +157,7 @@ impl<'lua> Functions<'lua> {
])?;
let wrap = lua
.load(WRAP_IMPL_LUA)
.set_name("=__runtime_wrap")
.set_name("=__scheduler_wrap")
.set_environment(wrap_env)
.into_function()?;

Expand Down Expand Up @@ -243,7 +243,7 @@ impl<'lua> Functions<'lua> {
])?;
let exit = lua
.load(EXIT_IMPL_LUA)
.set_name("=__runtime_exit")
.set_name("=__scheduler_exit")
.set_environment(exit_env)
.into_function()?;

Expand All @@ -260,7 +260,7 @@ impl<'lua> Functions<'lua> {

impl Functions<'_> {
/**
Injects [`Runtime`]-compatible functions into the given [`Lua`] instance.
Injects [`Scheduler`]-compatible functions into the given [`Lua`] instance.
This will overwrite the following functions:
Expand Down
6 changes: 3 additions & 3 deletions lib/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ mod exit;
mod functions;
mod queue;
mod result_map;
mod runtime;
mod scheduler;
mod status;
mod thread_id;
mod traits;
mod util;

pub use functions::Functions;
pub use runtime::Runtime;
pub use scheduler::Scheduler;
pub use status::Status;
pub use thread_id::ThreadId;
pub use traits::{IntoLuaThread, LuaRuntimeExt, LuaSpawnExt};
pub use traits::{IntoLuaThread, LuaSchedulerExt, LuaSpawnExt};
Loading

0 comments on commit 8e8647e

Please sign in to comment.