Skip to content

Commit 020e8a7

Browse files
committed
Impl FromLua for RegistryKey
1 parent 3ca7b49 commit 020e8a7

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/conversion.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,13 @@ impl<'lua> IntoLua<'lua> for &RegistryKey {
441441
}
442442
}
443443

444+
impl<'lua> FromLua<'lua> for RegistryKey {
445+
#[inline]
446+
fn from_lua(value: Value<'lua>, lua: &'lua Lua) -> Result<RegistryKey> {
447+
lua.create_registry_value(value)
448+
}
449+
}
450+
444451
impl<'lua> IntoLua<'lua> for bool {
445452
#[inline]
446453
fn into_lua(self, _: &'lua Lua) -> Result<Value<'lua>> {

tests/conversion.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
33
use std::ffi::{CStr, CString};
44

55
use maplit::{btreemap, btreeset, hashmap, hashset};
6-
use mlua::{AnyUserData, Error, Function, IntoLua, Lua, Result, Table, Thread, UserDataRef, Value};
6+
use mlua::{
7+
AnyUserData, Error, Function, IntoLua, Lua, RegistryKey, Result, Table, Thread, UserDataRef,
8+
Value,
9+
};
710

811
#[test]
912
fn test_value_into_lua() -> Result<()> {
@@ -254,6 +257,17 @@ fn test_registry_value_into_lua() -> Result<()> {
254257
Ok(())
255258
}
256259

260+
#[test]
261+
fn test_registry_key_from_lua() -> Result<()> {
262+
let lua = Lua::new();
263+
264+
let fkey = lua.load("function() return 1 end").eval::<RegistryKey>()?;
265+
let f = lua.registry_value::<Function>(&fkey)?;
266+
assert_eq!(f.call::<_, i32>(())?, 1);
267+
268+
Ok(())
269+
}
270+
257271
#[test]
258272
fn test_conv_vec() -> Result<()> {
259273
let lua = Lua::new();

0 commit comments

Comments
 (0)