diff options
-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) |