diff options
author | kyren <kerriganw@gmail.com> | 2018-09-30 15:42:04 -0400 |
---|---|---|
committer | kyren <kerriganw@gmail.com> | 2018-09-30 15:42:04 -0400 |
commit | 167184ae76b37b53114f2818bbc48c83936a08f4 (patch) | |
tree | 153ac4ee37ff171a6c88770bd7c0e00b7d359ed7 /src/util.rs | |
parent | 8810c36979be268b1feede78a24e3f1ba5054271 (diff) | |
download | mlua-167184ae76b37b53114f2818bbc48c83936a08f4.zip |
Allow arbitrary [u8] Lua strings
Diffstat (limited to 'src/util.rs')
-rw-r--r-- | src/util.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/util.rs b/src/util.rs index 5723f33..544f9d7 100644 --- a/src/util.rs +++ b/src/util.rs @@ -220,8 +220,12 @@ pub unsafe fn pop_error(state: *mut ffi::lua_State, err_code: c_int) -> Error { } // Internally uses 4 stack spaces, does not call checkstack -pub unsafe fn push_string(state: *mut ffi::lua_State, s: &str) -> Result<()> { +pub unsafe fn push_string<S: ?Sized + AsRef<[u8]>>( + state: *mut ffi::lua_State, + s: &S, +) -> Result<()> { protect_lua_closure(state, 0, 1, |state| { + let s = s.as_ref(); ffi::lua_pushlstring(state, s.as_ptr() as *const c_char, s.len()); }) } |