Skip to content

Commit

Permalink
Change internal variables and functions called "lua" to "luau"
Browse files Browse the repository at this point in the history
  • Loading branch information
jackTabsCode committed Jun 25, 2024
1 parent 95bfcdc commit 7b4f92f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/commands/sync/codegen/flat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn asset_path(file_path: &str, strip_dir: &str, strip_extension: bool) -> anyhow
.map(|s| s.to_string())
}

pub fn generate_lua(
pub fn generate_luau(
lockfile: &LockFile,
strip_dir: &str,
strip_extension: bool,
Expand Down
18 changes: 9 additions & 9 deletions src/commands/sync/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ use crate::{commands::sync::config::CodegenStyle, LockFile};
mod flat;
mod nested;

pub fn generate_lua(
pub fn generate_luau(
lockfile: &LockFile,
strip_dir: &str,
style: &CodegenStyle,
strip_extension: bool,
) -> anyhow::Result<String> {
match style {
CodegenStyle::Flat => flat::generate_lua(lockfile, strip_dir, strip_extension),
CodegenStyle::Nested => nested::generate_lua(lockfile, strip_dir, strip_extension),
CodegenStyle::Flat => flat::generate_luau(lockfile, strip_dir, strip_extension),
CodegenStyle::Nested => nested::generate_luau(lockfile, strip_dir, strip_extension),
}
}

Expand Down Expand Up @@ -55,13 +55,13 @@ mod tests {
}

#[test]
fn generate_lua() {
fn generate_luau() {
let lockfile = test_lockfile();

let lua = super::flat::generate_lua(&lockfile, "assets", false).unwrap();
let lua = super::flat::generate_luau(&lockfile, "assets", false).unwrap();
assert_eq!(lua, "return {\n\t[\"/bar/baz.png\"] = \"rbxassetid://2\",\n\t[\"/foo.png\"] = \"rbxassetid://1\"\n}");

let lua = super::flat::generate_lua(&lockfile, "assets", true).unwrap();
let lua = super::flat::generate_luau(&lockfile, "assets", true).unwrap();
assert_eq!(lua, "return {\n\t[\"/bar/baz\"] = \"rbxassetid://2\",\n\t[\"/foo\"] = \"rbxassetid://1\"\n}");
}

Expand All @@ -77,15 +77,15 @@ mod tests {
}

#[test]
fn generate_lua_nested() {
fn generate_luau_nested() {
let lockfile = test_lockfile();

let lua = super::nested::generate_lua(&lockfile, "assets", false).unwrap();
let lua = super::nested::generate_luau(&lockfile, "assets", false).unwrap();
assert_eq!(
lua,
"return {\n bar = {\n [\"baz.png\"] = \"rbxassetid://2\",\n },\n [\"foo.png\"] = \"rbxassetid://1\",\n}");

let lua = super::nested::generate_lua(&lockfile, "assets", true).unwrap();
let lua = super::nested::generate_luau(&lockfile, "assets", true).unwrap();
assert_eq!(
lua,
"return {\n bar = {\n baz = \"rbxassetid://2\",\n },\n foo = \"rbxassetid://1\",\n}");
Expand Down
8 changes: 4 additions & 4 deletions src/commands/sync/codegen/nested/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ trait AstFormat {

#[derive(Debug)]
pub(crate) enum AstTarget {
Lua,
Luau,
Typescript { output_dir: String },
}

Expand Down Expand Up @@ -98,7 +98,7 @@ pub(crate) struct ReturnStatement(pub Expression, pub AstTarget);
impl AstFormat for ReturnStatement {
fn fmt_ast(&self, output: &mut AstStream) -> fmt::Result {
match output.target {
AstTarget::Lua => {
AstTarget::Luau => {
write!(output, "return ")
}
AstTarget::Typescript { output_dir } => {
Expand Down Expand Up @@ -150,7 +150,7 @@ pub(crate) struct Table {
impl AstFormat for Table {
fn fmt_ast(&self, output: &mut AstStream<'_, '_>) -> fmt::Result {
let assignment = match output.target {
AstTarget::Lua => " = ",
AstTarget::Luau => " = ",
AstTarget::Typescript { .. } => ": ",
};

Expand Down Expand Up @@ -179,7 +179,7 @@ impl AstFormat for String {
write!(output, "{}", self)
} else {
match output.target {
AstTarget::Lua => write!(output, "[\"{}\"]", self),
AstTarget::Luau => write!(output, "[\"{}\"]", self),
AstTarget::Typescript { .. } => write!(output, "\"{}\"", self),
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/commands/sync/codegen/nested/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ fn generate_expressions(
Ok(build_table(&NestedTable::Folder(root)))
}

pub fn generate_lua(
pub fn generate_luau(
lockfile: &LockFile,
strip_dir: &str,
strip_extension: bool,
) -> anyhow::Result<String> {
generate_code(
generate_expressions(lockfile, strip_dir, strip_extension)
.context("Failed to create nested expressions")?,
AstTarget::Lua,
AstTarget::Luau,
)
}

Expand Down
15 changes: 9 additions & 6 deletions src/commands/sync/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use self::state::SyncState;
use crate::{asset::Asset, cli::SyncArgs, FileEntry, LockFile};
use anyhow::Context;
use codegen::{generate_lua, generate_ts};
use codegen::{generate_luau, generate_ts};
use config::SyncConfig;
use log::{debug, info, warn};
use std::{collections::VecDeque, path::Path};
Expand Down Expand Up @@ -146,17 +146,20 @@ pub async fn sync(args: SyncArgs, existing_lockfile: LockFile) -> anyhow::Result
)
}));

let lua_filename = format!("{}.{}", state.output_name, "luau");
let lua_output = generate_lua(
let luau_filename = format!("{}.{}", state.output_name, "luau");
let luau_output = generate_luau(
&state.new_lockfile,
asset_dir_str,
&state.style,
state.strip_extension,
);

write(Path::new(&state.write_dir).join(lua_filename), lua_output?)
.await
.context("Failed to write output Luau file")?;
write(
Path::new(&state.write_dir).join(luau_filename),
luau_output?,
)
.await
.context("Failed to write output Luau file")?;

if state.typescript {
let ts_filename = format!("{}.d.ts", state.output_name);
Expand Down

0 comments on commit 7b4f92f

Please sign in to comment.