Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ assets/scripts/tlconfig.lua

/assets/**/*.lad.json
/docs/src/ladfiles/*.lad.json
/assets/**/bindings.lua
9 changes: 9 additions & 0 deletions .luarc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json",
"workspace.library": [
"assets/definitions"
],
"runtime.version": "Lua 5.4",
"hint.enable": false,
"diagnostics.workspaceDelay": 30000
}
19 changes: 14 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ default = [
"bevy_core_pipeline_bindings",
]

lua = [
"bevy_mod_scripting_lua",
"bevy_mod_scripting_functions/lua_bindings",
] ## lua

# lua
lua = ["bevy_mod_scripting_lua", "bevy_mod_scripting_functions/lua_bindings"]
# one of these must be selected
lua51 = ["bevy_mod_scripting_lua/lua51", "lua"]
lua52 = ["bevy_mod_scripting_lua/lua52", "lua"]
Expand All @@ -56,6 +55,10 @@ lua54 = ["bevy_mod_scripting_lua/lua54", "lua"]
luajit = ["bevy_mod_scripting_lua/luajit", "lua"]
luajit52 = ["bevy_mod_scripting_lua/luajit52", "lua"]
luau = ["bevy_mod_scripting_lua/luau", "lua"]
lua_language_server_files = [
"ladfile_builder",
"ladfile_builder/lua_language_server_files",
]

# bindings
core_functions = ["bevy_mod_scripting_functions/core_functions"]
Expand Down Expand Up @@ -111,8 +114,10 @@ bevy_mod_scripting_functions = { workspace = true }
bevy_mod_scripting_derive = { workspace = true }
bevy_mod_scripting_asset = { workspace = true }
bevy_mod_scripting_bindings = { workspace = true }
bevy_mod_scripting_bindings_domain = { workspace = true }
bevy_mod_scripting_display = { workspace = true }
bevy_mod_scripting_script = { workspace = true }
ladfile_builder = { workspace = true, optional = true }

[workspace.dependencies]
# local crates
Expand All @@ -127,8 +132,10 @@ bevy_mod_scripting_lua = { path = "crates/languages/bevy_mod_scripting_lua", ver
bevy_mod_scripting_rhai = { path = "crates/languages/bevy_mod_scripting_rhai", version = "0.16.0", default-features = false }
bevy_mod_scripting_asset = { path = "crates/bevy_mod_scripting_asset", version = "0.16.0", default-features = false }
bevy_mod_scripting_bindings = { path = "crates/bevy_mod_scripting_bindings", version = "0.16.0", default-features = false }
bevy_mod_scripting_bindings_domain = { path = "crates/bevy_mod_scripting_bindings_domain", version = "0.16.0", default-features = false }
bevy_mod_scripting_display = { path = "crates/bevy_mod_scripting_display", version = "0.16.0", default-features = false }
bevy_mod_scripting_script = { path = "crates/bevy_mod_scripting_script", version = "0.16.0", default-features = false }
lua_language_server_lad_backend = { path = "crates/lad_backends/lua_language_server_lad_backend", version = "0.16.0", default-features = false }

# bevy

Expand Down Expand Up @@ -215,7 +222,7 @@ pretty_assertions = { version = "1.4", default-features = false, features = [
"std",
] }
manifest-dir-macros = { version = "0.1.18", default-features = false }
assert_cmd = { version = "2.0", default-features = false }
assert_cmd = { version = "2.1", default-features = false }
tokio = { version = "1", default-features = false }
bevy_console = { version = "0.14", default-features = false }
tracing-tracy = { version = "0.11", default-features = false }
Expand Down Expand Up @@ -260,6 +267,7 @@ members = [
"crates/testing_crates/script_integration_test_harness",
"crates/bevy_mod_scripting_derive",
"crates/ladfile",
"crates/lad_backends/lua_language_server_lad_backend",
"crates/lad_backends/mdbook_lad_preprocessor",
"crates/ladfile_builder",
"crates/bevy_system_reflection",
Expand All @@ -268,6 +276,7 @@ members = [
"crates/bevy_mod_scripting_bindings",
"crates/bevy_mod_scripting_display",
"crates/bevy_mod_scripting_script",
"crates/bevy_mod_scripting_bindings_domain",
]
resolver = "2"
exclude = ["codegen", "crates/macro_tests", "xtask"]
Expand Down
56 changes: 29 additions & 27 deletions assets/scripts/game_of_life.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,35 @@ info("Lua: The game_of_life.lua script just got loaded")

math.randomseed(os.time())

function fetch_life_state()
-- find the first entity with life state
local i,v = next(world.query():component(LifeState):build())
function fetch_life_state()
-- find the first entity with life state
local i, v = next(world.query():component(LifeState):build())
return v:components()[1]
end
end

function on_script_loaded()
info("Lua: Hello! I am initiating the game of life simulation state with randomness!")
info("Lua: Click on the screen to set cells alive after running the `gol start` command")

local life_state = fetch_life_state()

local cells = life_state.cells

-- set some cells alive
for _=1,1000 do
for _ = 1, 1000 do
local index = math.random(#cells)
cells[index] = 255
end
end
end

function on_click(x,y)
function on_click(x, y)
-- get the settings
info("Lua: Clicked at x: " .. x .. " y: " .. y)
local life_state = fetch_life_state()
local cells = life_state.cells

local settings = world.get_resource(Settings)

local dimensions = settings.physical_grid_dimensions
local screen = settings.display_grid_dimensions

Expand All @@ -51,18 +53,18 @@ function on_click(x,y)

-- toggle a bunch of cells around if they exist
local cell_offsets = {
{0,0},
{1,0},
{0,1},
{1,1},
{-1,0},
{0,-1},
{-1,-1},
{1,-1},
{-1,1}
{ 0, 0 },
{ 1, 0 },
{ 0, 1 },
{ 1, 1 },
{ -1, 0 },
{ 0, -1 },
{ -1, -1 },
{ 1, -1 },
{ -1, 1 }
}

for _,offset in pairs(cell_offsets) do
for _, offset in pairs(cell_offsets) do
local offset_x = offset[1]
local offset_y = offset[2]
local new_index = index + offset_x + offset_y * dimension_x
Expand All @@ -81,10 +83,10 @@ function on_update()

-- primitives are passed by value to lua, keep a hold of old state but turn 255's into 1's
local prev_state = {}
for v in pairs(cells) do
prev_state[#prev_state+1] = (not(v == 0)) and 1 or 0
for v in pairs(cells) do
prev_state[#prev_state + 1] = (not (v == 0)) and 1 or 0
end
for i=1,(dimension_x * dimension_y) do
for i = 1, (dimension_x * dimension_y) do
-- wrap around the north and south edges
local north = prev_state[i - dimension_x] or prev_state[i + dimension_x * (dimension_y - 1)]
local south = prev_state[i + dimension_x] or prev_state[i - dimension_x * (dimension_y - 1)]
Expand All @@ -95,13 +97,13 @@ function on_update()
local northwest = prev_state[i - dimension_x - 1] or 0
local southwest = prev_state[i + dimension_x - 1] or 0

local neighbours = north + south + east + west
local neighbours = north + south + east + west
+ northeast + southeast + northwest + southwest

-- was dead and got 3 neighbours now
if prev_state[i] == 0 and neighbours == 3 then
cells[i] = 255
-- was alive and should die now
-- was alive and should die now
elseif prev_state[i] == 1 and ((neighbours < 2) or (neighbours > 3)) then
cells[i] = 0
end
Expand All @@ -114,7 +116,7 @@ function on_script_unloaded()
-- set state to 0's
local life_state = fetch_life_state()
local cells = life_state.cells
for i=1,#cells do
for i = 1, #cells do
cells[i] = 0
end
end
end
2 changes: 2 additions & 0 deletions crates/bevy_mod_scripting_bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ bevy_mod_scripting_asset = { workspace = true }
bevy_mod_scripting_derive = { workspace = true }
bevy_mod_scripting_display = { workspace = true }
bevy_mod_scripting_script = { workspace = true }
bevy_mod_scripting_bindings_domain = { workspace = true }
bevy_system_reflection = { workspace = true }
bevy_diagnostic = { workspace = true }
bevy_ecs = { workspace = true }
Expand All @@ -30,6 +31,7 @@ itertools = { workspace = true }
profiling = { workspace = true }
bevy_asset = { workspace = true }
variadics_please = { workspace = true }
serde = { workspace = true }

[dev-dependencies]
pretty_assertions = { workspace = true }
Expand Down
10 changes: 6 additions & 4 deletions crates/bevy_mod_scripting_bindings/src/docgen/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ variadics_please::all_tuples!(impl_documentable, 0, 13, T);

#[cfg(test)]
mod test {
use bevy_mod_scripting_bindings_domain::ReflectionPrimitiveKind;

use crate::{
docgen::typed_through::UntypedWrapperKind,
function::from::{Mut, Ref, Val},
Expand All @@ -252,15 +254,15 @@ mod test {
assert_eq!(info.arg_info[1].type_id, TypeId::of::<f32>());

match info.arg_info[0].type_info.as_ref().unwrap() {
ThroughTypeInfo::TypeInfo(type_info) => {
assert_eq!(type_info.type_id(), TypeId::of::<i32>());
ThroughTypeInfo::Primitive(prim) => {
assert_eq!(*prim, ReflectionPrimitiveKind::I32);
}
_ => panic!("Expected TypeInfo"),
}

match info.arg_info[1].type_info.as_ref().unwrap() {
ThroughTypeInfo::TypeInfo(type_info) => {
assert_eq!(type_info.type_id(), TypeId::of::<f32>());
ThroughTypeInfo::Primitive(prim) => {
assert_eq!(*prim, ReflectionPrimitiveKind::F32);
}
_ => panic!("Expected TypeInfo"),
}
Expand Down
Loading
Loading