Created
March 3, 2017 10:39
-
-
Save VictorKoenders/646393fe46dd6c6f282968a69fec6183 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate hlua; | |
const LUA: &'static str = r#" | |
data:extend({ | |
{ | |
type = "font", | |
name = "default", | |
from = "default", | |
size = 14 | |
} | |
}) | |
"#; | |
type LuaTable<'a, 'b> = hlua::LuaTable<hlua::PushGuard<&'a mut hlua::Lua<'b>>>; | |
#[derive(Debug)] | |
enum Data { | |
} | |
impl Data { | |
pub fn from_table(table: &mut LuaTable) { | |
for (key, value) in table.iter().filter_map(|e|e) { | |
let key: String = key; | |
let value: hlua::AnyLuaValue = value; | |
match value { | |
hlua::AnyLuaValue::LuaOther => println!("{:?} is of type \"other\"", key), | |
hlua::AnyLuaValue::LuaNumber(val) => println!("{:?} = {}", key, val), | |
_ => unreachable!("{:?}", value) | |
} | |
} | |
} | |
} | |
fn main(){ | |
let mut lua = hlua::Lua::new(); | |
lua.openlibs(); | |
let str = String::from(r#" | |
data = {} | |
data["__length"] = 0; | |
function data:extend(table) | |
for _, value in ipairs(table) do | |
self[self["__length"]] = value | |
self["__length"] = self["__length"] + 1 | |
end | |
end | |
"#) + LUA; | |
lua.execute::<()>(&str).unwrap(); | |
let value: hlua::AnyLuaValue = lua.get("data").unwrap(); | |
let value = match value { | |
hlua::AnyLuaValue::LuaOther => Data::from_table(&mut lua.get::<LuaTable, &'static str>("data").unwrap()), | |
_ => unreachable!("{:?}", value) | |
}; | |
println!("{:#?}", value); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs | |
Running `target\debug\marapr.exe` | |
"__length" = 1 | |
"0" is of type "other" | |
thread 'main' panicked at 'PANIC: unprotected error in call to Lua API (invalid key to 'next') | |
', C:\Users\vkoenders.INTRANET\.cargo\registry\src\github.com-1ecc6299db9ec823\hlua-0.3.1\src\lib.rs:300 | |
stack backtrace: | |
0: 0x7ff605f0a18f - std::sys_common::backtrace::_print | |
at C:\projects\rust\src\libstd\sys_common\backtrace.rs:94 | |
1: 0x7ff605f112cc - std::panicking::default_hook::{{closure}} | |
at C:\projects\rust\src\libstd\panicking.rs:354 | |
2: 0x7ff605f10b8f - std::panicking::default_hook | |
at C:\projects\rust\src\libstd\panicking.rs:371 | |
3: 0x7ff605f11711 - std::panicking::rust_panic_with_hook | |
at C:\projects\rust\src\libstd\panicking.rs:549 | |
4: 0x7ff605f115c8 - std::panicking::begin_panic<collections::string::String> | |
at C:\projects\rust\src\libstd\panicking.rs:511 | |
5: 0x7ff605f114e4 - std::panicking::begin_panic_fmt | |
at C:\projects\rust\src\libstd\panicking.rs:495 | |
6: 0x7ff605f00fcd - hlua::{{impl}}::new::panic | |
at C:\Users\vkoenders.INTRANET\.cargo\registry\src\github.com-1ecc6299db9ec823\hlua-0.3.1\src\lib.rs:300 | |
7: 0x7ff605f24dfb - luaD_throw | |
at c:\users\vkoenders.intranet\.cargo\registry\src\github.com-1ecc6299db9ec823\lua52-sys-0.1.0\lua\src\ldo.c:117 | |
8: 0x7ff605f229a2 - luaG_errormsg | |
at c:\users\vkoenders.intranet\.cargo\registry\src\github.com-1ecc6299db9ec823\lua52-sys-0.1.0\lua\src\ldebug.c:599 | |
9: 0x7ff605f22875 - luaG_runerror | |
at c:\users\vkoenders.intranet\.cargo\registry\src\github.com-1ecc6299db9ec823\lua52-sys-0.1.0\lua\src\ldebug.c:608 | |
10: 0x7ff605f2b245 - findindex | |
at c:\users\vkoenders.intranet\.cargo\registry\src\github.com-1ecc6299db9ec823\lua52-sys-0.1.0\lua\src\ltable.c:163 | |
11: 0x7ff605f2aa49 - luaH_next | |
at c:\users\vkoenders.intranet\.cargo\registry\src\github.com-1ecc6299db9ec823\lua52-sys-0.1.0\lua\src\ltable.c:170 | |
12: 0x7ff605f1f774 - lua_next | |
at c:\users\vkoenders.intranet\.cargo\registry\src\github.com-1ecc6299db9ec823\lua52-sys-0.1.0\lua\src\lapi.c:1120 | |
13: 0x7ff605ef17e2 - hlua::lua_tables::{{impl}}::next<hlua::PushGuard<&mut hlua::Lua>,collections::string::String,hlua::any::AnyLuaValue> | |
at C:\Users\vkoenders.INTRANET\.cargo\registry\src\github.com-1ecc6299db9ec823\hlua-0.3.1\src\lua_tables.rs:434 | |
14: 0x7ff605efb450 - core::iter::iterator::{{impl}}::next<hlua::lua_tables::LuaTableIterator<hlua::PushGuard<&mut hlua::Lua>, collections::string::String, hlua::any::AnyLuaValue>> | |
at C:\projects\rust\src\libcore\iter\iterator.rs:2197 | |
15: 0x7ff605efcd0b - core::iter::{{impl}}::next<(collections::string::String, hlua::any::AnyLuaValue),hlua::lua_tables::LuaTableIterator<hlua::PushGuard<&mut hlua::Lua>, collections::string::String, hlua::any::AnyLuaValue>,closure> | |
at C:\projects\rust\src\libcore\iter\mod.rs:1175 | |
16: 0x7ff605efd066 - marapr::Data::from_table | |
at d:\Development\Personal\marapr\src\main.rs:22 | |
17: 0x7ff605efd77c - marapr::main | |
at d:\Development\Personal\marapr\src\main.rs:52 | |
18: 0x7ff605f121d1 - panic_unwind::__rust_maybe_catch_panic | |
at C:\projects\rust\src\libpanic_unwind\lib.rs:98 | |
19: 0x7ff605f119ea - std::rt::lang_start | |
at C:\projects\rust\src\libstd\rt.rs:51 | |
20: 0x7ff605efda0b - main | |
21: 0x7ff605f4b758 - __scrt_common_main_seh | |
at f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:253 | |
22: 0x7ff97c518363 - BaseThreadInitThunk | |
error: process didn't exit successfully: `target\debug\marapr.exe` (exit code: 101) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment