Skip to content

Commit

Permalink
build: update to latest piccolo. (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
zicklag committed Dec 8, 2023
1 parent 53f94e9 commit 831a7d8
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 106 deletions.
80 changes: 40 additions & 40 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion framework_crates/bones_bevy_renderer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,10 @@ fn step_bones_game(world: &mut World) {
asset_server.handle_asset_changes(|asset_server, handle| {
let mut bones_egui_textures =
game.shared_resource_mut::<bones::EguiTextures>().unwrap();
let mut asset = asset_server.get_asset_untyped_mut(handle).unwrap();
let Some(mut asset) = asset_server.get_asset_untyped_mut(handle) else {
// There was an issue loading the asset. The error will have been logged.
return;
};

// TODO: hot reload changed fonts.

Expand Down
4 changes: 2 additions & 2 deletions framework_crates/bones_scripting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tracing = "0.1"
bevy_tasks = "0.11"
bones_lib = { version = "0.3", path = "../bones_lib" }
bones_asset = { version = "0.3", path = "../bones_asset" }
piccolo = { git = "https://github.com/kyren/piccolo.git" }
piccolo = { git = "https://github.com/kyren/piccolo.git", rev = "d25ef38" }
gc-arena = { git = "https://github.com/kyren/gc-arena.git" }
gc-arena-derive = { git = "https://github.com/kyren/gc-arena.git" }
send_wrapper = "0.6.0"
Expand All @@ -26,5 +26,5 @@ elsa = "1.9"
wasm-bindgen-futures = "0.4"

[dev-dependencies]
piccolo = { git = "https://github.com/kyren/piccolo.git" }
piccolo = { git = "https://github.com/kyren/piccolo.git", rev = "d25ef38" }

35 changes: 17 additions & 18 deletions framework_crates/bones_scripting/src/lua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use bones_asset::dashmap::mapref::one::{MappedRef, MappedRefMut};
use bones_lib::ecs::utils::*;

use parking_lot::Mutex;
pub use piccolo;
use piccolo::{
compiler::{LineNumber, ParseError},
registry::{Fetchable, Stashable},
Expand Down Expand Up @@ -64,7 +65,7 @@ impl SessionPlugin for LuaPluginLoaderSessionPlugin {
world: &World| {
engine.exec(|lua| {
Frozen::<Freeze![&'freeze World]>::in_scope(world, |world| {
lua.run(|ctx| {
lua.enter(|ctx| {
let env = ctx.singletons().get(ctx, bindings::env);
let worldref = WorldRef(world);
worldref.add_to_env(ctx, env);
Expand All @@ -87,10 +88,10 @@ impl SessionPlugin for LuaPluginLoaderSessionPlugin {

for (has_run, closure) in &mut systems.startup {
if !*has_run {
let executor = lua.run(|ctx| {
let closure = ctx.state.registry.fetch(closure);
let executor = lua.enter(|ctx| {
let closure = ctx.registry().fetch(closure);
let ex = Executor::start(ctx, closure.into(), ());
ctx.state.registry.stash(&ctx, ex)
ctx.registry().stash(&ctx, ex)
});
if let Err(e) = lua.execute::<()>(&executor) {
tracing::error!("Error running lua plugin system: {e}");
Expand All @@ -102,10 +103,10 @@ impl SessionPlugin for LuaPluginLoaderSessionPlugin {

for (stage, closure) in &systems.core_stages {
if stage == &lua_stage {
let executor = lua.run(|ctx| {
let closure = ctx.state.registry.fetch(closure);
let executor = lua.enter(|ctx| {
let closure = ctx.registry().fetch(closure);
let ex = Executor::start(ctx, closure.into(), ());
ctx.state.registry.stash(&ctx, ex)
ctx.registry().stash(&ctx, ex)
});
if let Err(e) = lua.execute::<()>(&executor) {
tracing::error!("Error running lua plugin system: {e}");
Expand Down Expand Up @@ -150,8 +151,7 @@ impl WorldRef {

/// Add this world
fn add_to_env<'gc>(&self, ctx: Context<'gc>, env: Table<'gc>) {
ctx.state
.globals
ctx.globals()
.set(ctx, "world", self.clone().into_userdata(ctx))
.unwrap();
for (name, metatable) in [
Expand Down Expand Up @@ -227,11 +227,11 @@ impl LuaSingletons {
"Encountered two functions with different return types and \
the same function pointer.",
);
ctx.state.registry.fetch(stashed)
ctx.registry().fetch(stashed)
} else {
drop(map); // Make sure we don't deadlock
let v = singleton(ctx);
let stashed = ctx.state.registry.stash(&ctx, v);
let stashed = ctx.registry().stash(&ctx, v);
self.singletons.borrow_mut().insert(id, Box::new(stashed));
v
}
Expand All @@ -242,9 +242,9 @@ impl Default for EngineState {
fn default() -> Self {
// Initialize an empty lua engine and our lua data.
let mut lua = Lua::core();
lua.try_run(|ctx| {
lua.try_enter(|ctx| {
// Insert our lua singletons.
ctx.state.globals.set(
ctx.globals().set(
ctx,
"luasingletons",
AnyUserData::new_static(&ctx, LuaSingletons::default()),
Expand Down Expand Up @@ -317,7 +317,7 @@ impl LuaEngine {
// Wrap world reference so that it can be converted to lua userdata.
let worldref = WorldRef(world);

let executor = lua.try_run(|ctx| {
let executor = lua.try_enter(|ctx| {
// Fetch the env table
let env = self.state.data.get(ctx, bindings::env);

Expand All @@ -342,15 +342,14 @@ impl LuaEngine {
let closure = compiled_scripts.get(&cid);

Ok::<_, PrototypeError>(match closure {
Some(closure) => ctx.state.registry.fetch(closure),
Some(closure) => ctx.registry().fetch(closure),
None => {
let asset = asset_server.store.assets.get(&cid).unwrap();
let source = &asset.data.cast_ref::<LuaScript>().source;
// TODO: Provide a meaningfull name to loaded scripts.
let closure =
Closure::load_with_env(ctx, None, source.as_bytes(), env)?;
compiled_scripts
.insert(cid, ctx.state.registry.stash(&ctx, closure));
compiled_scripts.insert(cid, ctx.registry().stash(&ctx, closure));

closure
}
Expand All @@ -361,7 +360,7 @@ impl LuaEngine {
worldref.add_to_env(ctx, env);

let ex = Executor::start(ctx, closure.into(), ());
let ex = ctx.state.registry.stash(&ctx, ex);
let ex = ctx.registry().stash(&ctx, ex);
Ok(ex)
});

Expand Down
Loading

0 comments on commit 831a7d8

Please sign in to comment.