Skip to content

Commit

Permalink
Stub some scripting support
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkleiny committed Jul 10, 2024
1 parent 693c93e commit 3acba85
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 10 deletions.
8 changes: 8 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ serializer-json = ["common/json"]
serializer-ron = ["common/ron"]
serializer-xml = ["common/xml"]
serializer-yaml = ["common/yaml"]
lang-wren = ["scripting/wren"]
lang-lua = ["scripting/lua"]

[workspace.dependencies]
# shared dependencies
Expand All @@ -41,6 +43,7 @@ sdl = { package = "surreal-backend-sdl", path = "./backends/sdl", optional = tru
audio = { package = "surreal-audio", path = "./crates/audio", optional = true }
graphics = { package = "surreal-graphics", path = "./crates/graphics", optional = true }
input = { package = "surreal-input", path = "./crates/input", optional = true }
scripting = { package = "surreal-scripting", path = "./crates/scripting", optional = true }

[[example]]
name = "hello-world"
Expand Down
2 changes: 0 additions & 2 deletions crates/common/src/abstractions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@
//! scene.
pub use os::*;
pub use variant::*;

mod os;
mod variant;
6 changes: 3 additions & 3 deletions crates/graphics/src/animations.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Animation support.
use common::{FastHashMap, Identity, Lerp, Quat, StringName, TimeSpan, Vec2, Vec3};
use common::{FastHashMap, Lerp, Quat, StringName, TimeSpan, Vec2, Vec3};

use crate::{Color, Color32};

Expand Down Expand Up @@ -160,7 +160,7 @@ impl<T> AnimationTree<T> {
}

/// Evaluates the final value of the given keyframes by interpolation.
fn evaluate_keyframes<T: Identity + Lerp + Copy>(time: f32, keyframes: &[AnimationKeyFrame<T>]) -> T {
fn evaluate_keyframes<T: Default + Lerp + Copy>(time: f32, keyframes: &[AnimationKeyFrame<T>]) -> T {
for i in 0..keyframes.len() {
let keyframe = &keyframes[i];

Expand All @@ -174,7 +174,7 @@ fn evaluate_keyframes<T: Identity + Lerp + Copy>(time: f32, keyframes: &[Animati
}
}

T::ZERO
T::default()
}

#[cfg(test)]
Expand Down
13 changes: 13 additions & 0 deletions crates/scripting/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "surreal-scripting"
description = "Scripting engine for Surreal"
authors.workspace = true
edition.workspace = true
version.workspace = true

[dependencies]
common = { package = "surreal-common", path = "../common" }

[features]
wren = []
lua = []
38 changes: 38 additions & 0 deletions crates/scripting/src/lang.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//! Scripting language abstractions
use common::ToVirtualPath;
#[cfg(feature = "lua")]
pub use lua::*;
#[cfg(feature = "wren")]
pub use wren::*;

#[cfg(feature = "lua")]
mod lua;
#[cfg(feature = "wren")]
mod wren;

/// Represents a scripting language
pub trait ScriptLanguage {
/// Loads a script from the given path
fn load(path: impl ToVirtualPath) -> Result<Script, ScriptError>;
}

/// Represents a parsed script
pub struct Script {
module: ast::Module,
}

/// Represents an error that occurred while parsing a script
pub enum ScriptError {
NotFound,
ParseError,
}

mod ast {
//! The internal AST representation of a script
pub struct Module {}
pub enum Statement {}
pub enum Expression {}
pub enum Literal {}
}
12 changes: 12 additions & 0 deletions crates/scripting/src/lang/lua.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//! Lua support for Surreal
use super::*;

/// The Lua scripting language
pub struct Lua;

impl ScriptLanguage for Lua {
fn load(_path: impl ToVirtualPath) -> Result<Script, ScriptError> {
todo!()
}
}
25 changes: 25 additions & 0 deletions crates/scripting/src/lang/wren.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//! Wren support for surreal
use super::*;

/// The Wren scripting language and virtual machine.
pub struct Wren;

impl ScriptLanguage for Wren {
fn load(path: impl ToVirtualPath) -> Result<Script, ScriptError> {
let path = path.to_virtual_path();
let text = path.read_all_text().map_err(|_| ScriptError::ParseError)?;

parser::parse(&text).map_err(|_| ScriptError::ParseError)?;

todo!()
}
}

mod parser {
use super::*;

pub fn parse(text: &str) -> Result<ast::Module, ()> {
todo!()
}
}
10 changes: 10 additions & 0 deletions crates/scripting/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//! Scripting engine for Surreal
pub use lang::*;
pub use variant::*;

mod lang;
mod variant;

/// Represents a script in a scripting language
pub trait Script {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
maths::{Quat, Vec2, Vec3, Vec4},
strings::StringName,
};
use common::{Quat, StringName, Vec2, Vec3, Vec4};

/// A type that can hold varying different values.
///
Expand Down
1 change: 0 additions & 1 deletion editor/src/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub struct Project {

/// Top-level details for a [`Project`].
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ProjectDetails {
pub name: String,
pub path: String,
Expand Down

0 comments on commit 3acba85

Please sign in to comment.