mirror of
https://github.com/mlua-rs/mlua
synced 2026-06-08 16:05:43 +00:00
more reorganization, move simple type defines to types.rs module
This commit is contained in:
+3
-29
@@ -1,17 +1,13 @@
|
||||
use std::cell::{RefCell, Ref, RefMut};
|
||||
use std::marker::PhantomData;
|
||||
use std::collections::HashMap;
|
||||
use std::os::raw::c_void;
|
||||
use std::string::String as StdString;
|
||||
|
||||
use ffi;
|
||||
use error::*;
|
||||
use util::*;
|
||||
use lua::{FromLua, FromLuaMulti, ToLuaMulti, Callback, LuaRef, Lua};
|
||||
|
||||
/// A "light" userdata value. Equivalent to an unmanaged raw pointer.
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
pub struct LightUserData(pub *mut c_void);
|
||||
use types::{Callback, LuaRef};
|
||||
use lua::{FromLua, FromLuaMulti, ToLuaMulti, Lua};
|
||||
|
||||
/// Kinds of metamethods that can be overridden.
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||
@@ -400,33 +396,11 @@ impl<'lua> AnyUserData<'lua> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{LightUserData, UserData, MetaMethod, UserDataMethods};
|
||||
use super::{UserData, MetaMethod, UserDataMethods};
|
||||
use error::ExternalError;
|
||||
use string::String;
|
||||
use lua::{Function, Lua};
|
||||
|
||||
use std::os::raw::c_void;
|
||||
|
||||
#[test]
|
||||
fn test_lightuserdata() {
|
||||
let lua = Lua::new();
|
||||
let globals = lua.globals();
|
||||
lua.exec::<()>(
|
||||
r#"
|
||||
function id(a)
|
||||
return a
|
||||
end
|
||||
"#,
|
||||
None,
|
||||
).unwrap();
|
||||
let res = globals
|
||||
.get::<_, Function>("id")
|
||||
.unwrap()
|
||||
.call::<_, LightUserData>(LightUserData(42 as *mut c_void))
|
||||
.unwrap();
|
||||
assert_eq!(res, LightUserData(42 as *mut c_void));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_user_data() {
|
||||
struct UserData1(i64);
|
||||
|
||||
Reference in New Issue
Block a user