diff options
author | Martin Fischer <martin@push-f.com> | 2022-10-28 12:56:03 +0200 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2022-10-28 12:56:27 +0200 |
commit | f47ccc6bb07e8f5f2a71f50633c0c6bac4dfde37 (patch) | |
tree | 317a8aad10b457233ac71e22d7036bfda4eabb90 | |
parent | 3433e3dda8917fe02b3b225d5e2829d0ec64946e (diff) |
add gitpad.encode_uri_component Lua function
-rw-r--r-- | src/lua.rs | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -2,6 +2,7 @@ use std::fmt::Display; use std::path::Path; use std::str::from_utf8; +use percent_encoding::utf8_percent_encode; use rlua::Function; use rlua::HookTriggers; use rlua::Lua; @@ -47,6 +48,13 @@ pub fn lua_context<A>(run: impl FnOnce(rlua::Context) -> rlua::Result<A>) -> rlu .eval::<Table>() .expect("error in api.lua"); + api.set( + "encode_uri_component", + ctx.create_function(|_ctx, text: String| { + Ok(utf8_percent_encode(&text, percent_encoding::NON_ALPHANUMERIC).to_string()) + })?, + )?; + ctx.globals().raw_set("gitpad", api).unwrap(); run(ctx) |