Skip to content

Commit

Permalink
Fix lib build
Browse files Browse the repository at this point in the history
  • Loading branch information
eero-lehtinen committed Nov 2, 2024
1 parent 6f00567 commit 505cfe4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 43 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,11 @@ jobs:
- name: Rename lib
working-directory: ./target/${{ matrix.target }}/release
run: |
lib="parser_lua_module.${{ matrix.lib_ext }}"
if [ test -f "lib$lib" ]; then
mv "lib$lib" "$lib"
fi
mv *.${{ matrix.lib_ext }} "parser_lua_module-${{ matrix.target }}.${{ matrix.lib_ext }}"
- name: Upload the binaries
uses: softprops/action-gh-release@v2
with:
files: |
${{ env.ASSET }}
target/${{ matrix.target }}/release/parser_lua_module.${{ matrix.lib_ext }}
target/${{ matrix.target }}/release/parser_lua_module-${{ matrix.target }}.${{ matrix.lib_ext }}
81 changes: 43 additions & 38 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,47 +1,52 @@
use bevy_color::Color;
use clap::ValueEnum;
use cli::CliColorFormat;
use mlua::prelude::*;
mod cli;
mod formats;
mod gamut;

pub mod cli;
pub mod formats;
pub mod gamut;
#[cfg(not(target_arch = "wasm32"))]
mod lua {
use super::*;
use bevy_color::Color;
use clap::ValueEnum;
use cli::CliColorFormat;
use mlua::prelude::*;

fn gamut_clip(color: Color) -> Color {
if let Color::Oklcha(color) = color {
gamut::gamut_clip_preserve_chroma(color.into()).into()
} else {
color
fn gamut_clip(color: Color) -> Color {
if let Color::Oklcha(color) = color {
gamut::gamut_clip_preserve_chroma(color.into()).into()
} else {
color
}
}
}

fn version(_: &Lua, _: ()) -> LuaResult<&'static str> {
Ok(env!("CARGO_PKG_VERSION"))
}
fn version(_: &Lua, _: ()) -> LuaResult<&'static str> {
Ok(env!("CARGO_PKG_VERSION"))
}

fn color_to_hex(_: &Lua, (color, fmt): (String, Option<String>)) -> LuaResult<Option<String>> {
let color = if let Some(fmt) = fmt {
let parsed_fmt = CliColorFormat::from_str(&fmt, true).map_err(LuaError::RuntimeError)?;
match formats::parse_color(&color, parsed_fmt.into()) {
Some((c, _)) => c,
None => return Ok(None),
}
} else {
match formats::parse_color_unknown_format(&color) {
Some((c, _, _)) => c,
None => return Ok(None),
}
};
fn color_to_hex(_: &Lua, (color, fmt): (String, Option<String>)) -> LuaResult<Option<String>> {
let color = if let Some(fmt) = fmt {
let parsed_fmt =
CliColorFormat::from_str(&fmt, true).map_err(LuaError::RuntimeError)?;
match formats::parse_color(&color, parsed_fmt.into()) {
Some((c, _)) => c,
None => return Ok(None),
}
} else {
match formats::parse_color_unknown_format(&color) {
Some((c, _, _)) => c,
None => return Ok(None),
}
};

let color = gamut_clip(color);
let color = gamut_clip(color);

Ok(Some(formats::format_normalized_hex_no_alpha(color.into())))
}
Ok(Some(formats::format_normalized_hex_no_alpha(color.into())))
}

#[mlua::lua_module(skip_memory_check)]
fn parser_lua_module(lua: &Lua) -> LuaResult<LuaTable> {
let exports = lua.create_table()?;
exports.set("color_to_hex", lua.create_function(color_to_hex)?)?;
exports.set("version", lua.create_function(version)?)?;
Ok(exports)
#[mlua::lua_module(skip_memory_check)]
fn parser_lua_module(lua: &Lua) -> LuaResult<LuaTable> {
let exports = lua.create_table()?;
exports.set("color_to_hex", lua.create_function(color_to_hex)?)?;
exports.set("version", lua.create_function(version)?)?;
Ok(exports)
}
}

0 comments on commit 505cfe4

Please sign in to comment.