2024-01-27 19:54:11 +00:00
|
|
|
use std::{marker::PhantomData, sync::Arc};
|
2024-01-22 03:53:53 +00:00
|
|
|
|
|
|
|
use mlua_sys as lua;
|
|
|
|
|
|
|
|
pub mod state;
|
|
|
|
use state::*;
|
|
|
|
|
|
|
|
pub mod table;
|
|
|
|
use table::*;
|
|
|
|
|
|
|
|
pub mod function;
|
|
|
|
use function::*;
|
|
|
|
|
|
|
|
pub mod value;
|
|
|
|
use value::*;
|
|
|
|
|
2024-01-26 04:47:30 +00:00
|
|
|
pub mod guard;
|
|
|
|
use guard::*;
|
|
|
|
|
2024-01-26 20:43:26 +00:00
|
|
|
pub mod userdata;
|
|
|
|
use userdata::*;
|
2024-01-26 04:47:30 +00:00
|
|
|
|
2024-01-26 20:43:26 +00:00
|
|
|
pub mod util;
|
|
|
|
use util::*;
|
2024-01-26 04:47:30 +00:00
|
|
|
|
2024-01-29 01:02:12 +00:00
|
|
|
pub mod chunk;
|
|
|
|
use chunk::*;
|
|
|
|
|
2024-01-22 03:53:53 +00:00
|
|
|
fn main() -> Result<()> {
|
|
|
|
let lua = State::new();
|
2024-01-26 20:43:26 +00:00
|
|
|
lua.expose_libraries(&[StdLibrary::Debug, StdLibrary::Package]);
|
2024-01-22 03:53:53 +00:00
|
|
|
|
2024-01-26 04:47:30 +00:00
|
|
|
let globals = lua.globals()?;
|
|
|
|
|
2024-01-26 20:43:26 +00:00
|
|
|
let a = |_lua: &State, (num,): (i32,)| -> Result<i32> {
|
2024-01-26 04:47:30 +00:00
|
|
|
println!("Rust got number from lua: {}", num);
|
|
|
|
Ok(999)
|
|
|
|
};
|
|
|
|
|
|
|
|
let f = lua.create_function(a)?;
|
|
|
|
globals.set("native_test", f)?;
|
|
|
|
|
2024-01-29 01:02:12 +00:00
|
|
|
let ud = lua.create_userdata(UserdataProxy::<Vec2>::new())?;
|
2024-01-26 20:43:26 +00:00
|
|
|
globals.set("Vec2", ud)?;
|
2024-01-26 04:47:30 +00:00
|
|
|
|
2024-01-22 03:53:53 +00:00
|
|
|
let tbl = lua.create_table()?;
|
|
|
|
tbl.set("x", 10)?;
|
|
|
|
|
2024-01-26 04:47:30 +00:00
|
|
|
//let globals = lua.globals()?;
|
2024-01-22 03:53:53 +00:00
|
|
|
globals.set("X", tbl)?;
|
|
|
|
|
2024-01-29 01:02:12 +00:00
|
|
|
let chunk = lua.load("text.lua", r#"
|
2024-01-26 20:43:26 +00:00
|
|
|
require "util"
|
|
|
|
|
2024-01-22 03:53:53 +00:00
|
|
|
--[[function dump_table(tbl)
|
|
|
|
for k, v in pairs(tbl) do
|
|
|
|
if type(v) == "table" then
|
|
|
|
dump_table(v)
|
|
|
|
elseif type(v) == "function" then
|
|
|
|
|
|
|
|
else
|
|
|
|
print(k .. "=" .. tostring(v))
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
for k, v in pairs(_G) do
|
|
|
|
--print("Found global named " .. k)
|
|
|
|
|
|
|
|
if k == "X" then
|
|
|
|
--dump_table(v)
|
|
|
|
end
|
|
|
|
end]]--
|
|
|
|
|
|
|
|
function multiply_print(a, b)
|
2024-01-26 04:47:30 +00:00
|
|
|
print(a .. " * " .. b .. " = " .. a*b)
|
2024-01-22 03:53:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function multiply_ret(a, b)
|
|
|
|
return a * b
|
|
|
|
end
|
2024-01-26 04:47:30 +00:00
|
|
|
|
|
|
|
function say_number(a)
|
|
|
|
print("Lua says " .. a)
|
|
|
|
end
|
|
|
|
|
|
|
|
cool_num = 50
|
|
|
|
|
2024-01-29 01:02:12 +00:00
|
|
|
print("Lua is about to exec native_test")
|
2024-01-26 04:47:30 +00:00
|
|
|
local res = native_test(50)
|
|
|
|
print("Lua got " .. res .. " back from rust!")
|
|
|
|
|
2024-01-26 20:43:26 +00:00
|
|
|
print("Vec2: " .. dump_table(Vec2))
|
|
|
|
print("Meta Vec2: " .. dump_table(getmetatable(Vec2)))
|
2024-01-27 19:54:11 +00:00
|
|
|
|
2024-01-27 20:53:34 +00:00
|
|
|
--print("Vec2 is (" .. Vec2.x .. ", " .. Vec2.y .. ")")
|
2024-01-27 19:54:11 +00:00
|
|
|
|
|
|
|
local v1 = Vec2.new(50, 50)
|
|
|
|
print("v1 is (" .. v1.x .. ", " .. v1.y .. ")")
|
|
|
|
|
|
|
|
local v2 = Vec2.new(500, 500)
|
|
|
|
print("v2 is (" .. v2.x .. ", " .. v2.y .. ")")
|
|
|
|
|
2024-01-28 18:32:08 +00:00
|
|
|
local v_add = v1 + v2
|
2024-01-27 19:54:11 +00:00
|
|
|
v_add.x = 90
|
|
|
|
print("v_add is (" .. v_add.x .. ", " .. v_add.y .. ")")
|
2024-01-28 18:32:08 +00:00
|
|
|
|
|
|
|
function f1(v1, v2)
|
|
|
|
--print("f1 tb: " .. debug.traceback(1))
|
|
|
|
local v_add = v1:add(v2)
|
|
|
|
end
|
|
|
|
|
|
|
|
function f2(v1, v2)
|
|
|
|
--print("f2 tb: " .. debug.traceback(1))
|
|
|
|
f1(v1, v2)
|
|
|
|
end
|
|
|
|
|
|
|
|
function f3(v1, v2)
|
|
|
|
--print("f3 tb: " .. debug.traceback(1))
|
|
|
|
f2(v1, v2)
|
|
|
|
end
|
|
|
|
|
|
|
|
f3(v1, v2)
|
2024-01-29 01:02:12 +00:00
|
|
|
"#)?;
|
|
|
|
|
|
|
|
// I don't care about the result of this execution, so I set the result as a
|
|
|
|
// Value which can be anything
|
|
|
|
//
|
|
|
|
// Chunks can also be executed with: `chunk.execute(())?;`
|
|
|
|
let res = lua.execute_chunk::<_, Value>(&chunk, ());
|
2024-01-28 18:32:08 +00:00
|
|
|
|
|
|
|
// if unwrapped, the new lines in the message would be escaped making
|
|
|
|
// the traceback in the error difficult to read.
|
|
|
|
if let Err(e) = res {
|
|
|
|
panic!("{}", e);
|
|
|
|
}
|
2024-01-22 03:53:53 +00:00
|
|
|
|
2024-01-24 01:28:19 +00:00
|
|
|
unsafe {
|
|
|
|
assert_eq!(lua::lua_gettop(lua.state_ptr()), 0); // ensure that nothing is left on the stack
|
|
|
|
}
|
|
|
|
|
2024-01-22 03:53:53 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct LuaRef(Arc<i32>);
|
|
|
|
|
|
|
|
impl From<i32> for LuaRef {
|
|
|
|
fn from(value: i32) -> Self {
|
|
|
|
Self(Arc::new(value))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl LuaRef {
|
|
|
|
/// Creates a reference to what is at the top of the stack.
|
|
|
|
pub unsafe fn from_stack(state: &State) -> Result<Self> {
|
|
|
|
let s = state.state_ptr();
|
|
|
|
|
|
|
|
let r = lua::luaL_ref(s, lua::LUA_REGISTRYINDEX);
|
|
|
|
if r == lua::LUA_REFNIL {
|
|
|
|
Err(Error::Nil)
|
|
|
|
} else {
|
|
|
|
Ok(LuaRef::from(r))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-26 20:43:26 +00:00
|
|
|
impl<'a> PushToLuaStack<'a> for LuaRef {
|
2024-01-22 03:53:53 +00:00
|
|
|
unsafe fn push_to_lua_stack(&self, state: &State) -> Result<()> {
|
|
|
|
let s = state.state_ptr();
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
state.ensure_stack(1)?;
|
2024-01-26 04:47:30 +00:00
|
|
|
let top = lua::lua_gettop(s);
|
|
|
|
let ty = lua::lua_rawgeti(s, lua::LUA_REGISTRYINDEX, *self.0 as i64);
|
|
|
|
let new_top = lua::lua_gettop(s);
|
|
|
|
|
|
|
|
if ty == lua::LUA_TNIL || ty == lua::LUA_TNONE || top == new_top {
|
|
|
|
return Err(Error::Nil);
|
|
|
|
}
|
2024-01-22 03:53:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, thiserror::Error)]
|
|
|
|
pub enum Error {
|
2024-01-28 18:32:08 +00:00
|
|
|
#[error("Syntax error: {0}")]
|
|
|
|
Syntax(String),
|
2024-01-22 03:53:53 +00:00
|
|
|
/// An error returned from lua
|
2024-01-26 04:47:30 +00:00
|
|
|
#[error("Lua runtime error: {0}")]
|
2024-01-22 03:53:53 +00:00
|
|
|
Runtime(String),
|
2024-01-28 18:32:08 +00:00
|
|
|
#[error("Error when running a __gc metamethod")]
|
|
|
|
GcFailure(String),
|
2024-01-22 03:53:53 +00:00
|
|
|
/// Ran into a not enough memory error when trying to grow the lua stack.
|
2024-01-28 18:32:08 +00:00
|
|
|
#[error("Failed to allocate memory")]
|
|
|
|
MemoryAlloc,
|
2024-01-22 03:53:53 +00:00
|
|
|
#[error("Ran into a nill value on the stack")]
|
|
|
|
Nil,
|
|
|
|
#[error("Unexpected type, expected {0} but got {1}")]
|
2024-01-26 04:47:30 +00:00
|
|
|
UnexpectedType(String, String),
|
2024-01-28 18:32:08 +00:00
|
|
|
#[error("bad argument #{arg_index}{} to `{}` ({error})",
|
|
|
|
.arg_name.clone().map(|a| format!(" (name: {})", a)).unwrap_or("".to_string()),
|
|
|
|
.func.clone().unwrap_or("Unknown".to_string())
|
|
|
|
)]
|
2024-01-26 04:47:30 +00:00
|
|
|
BadArgument {
|
|
|
|
func: Option<String>,
|
|
|
|
arg_index: i32,
|
|
|
|
arg_name: Option<String>,
|
|
|
|
/// the error that describes what was wrong for this argument
|
2024-01-28 16:26:30 +00:00
|
|
|
#[source]
|
2024-01-26 04:47:30 +00:00
|
|
|
error: Arc<Error>
|
|
|
|
},
|
2024-01-27 20:53:34 +00:00
|
|
|
#[error("Incorrect number of arguments, expected {arg_expected}, got {arg_count}")]
|
|
|
|
IncorrectArgCount {
|
|
|
|
arg_expected: i32,
|
|
|
|
arg_count: i32,
|
|
|
|
},
|
2024-01-26 04:47:30 +00:00
|
|
|
#[error("There is already a registry entry with the key {0}")]
|
2024-01-28 16:26:30 +00:00
|
|
|
RegistryConflict(String),
|
|
|
|
#[error("Userdata types did not match")]
|
|
|
|
UserdataMismatch,
|
|
|
|
#[error("Missing meta table for userdata")]
|
|
|
|
MissingMetatable,
|
|
|
|
#[error("An error occurred when attempting to convert from a ValueVec at value index {value_idx}, cause: {error}")]
|
|
|
|
ValueVecError {
|
|
|
|
value_idx: i32,
|
|
|
|
#[source]
|
|
|
|
error: Arc<Error>,
|
|
|
|
},
|
2024-01-22 03:53:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Error {
|
|
|
|
pub fn runtime(msg: &str) -> Self {
|
|
|
|
Self::Runtime(msg.to_string())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn unexpected_type(expected: &str, got: &str) -> Self {
|
|
|
|
Self::UnexpectedType(expected.to_string(), got.to_string())
|
|
|
|
}
|
2024-01-26 04:47:30 +00:00
|
|
|
|
|
|
|
/// Throw the error in lua.
|
|
|
|
///
|
|
|
|
/// This method never returns
|
|
|
|
pub unsafe fn throw_lua(self, lua: *mut lua::lua_State) -> ! {
|
2024-01-27 20:53:34 +00:00
|
|
|
let msg = format!("{}\0", self);
|
2024-01-26 04:47:30 +00:00
|
|
|
let msg_c = msg.as_ptr() as *const i8;
|
|
|
|
lua::luaL_error(lua, msg_c);
|
2024-01-26 20:43:26 +00:00
|
|
|
unreachable!();
|
2024-01-26 04:47:30 +00:00
|
|
|
}
|
2024-01-22 03:53:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// A result for use with lua functions
|
|
|
|
type Result<T> = core::result::Result<T, Error>;
|
|
|
|
|
2024-01-26 20:43:26 +00:00
|
|
|
pub trait PushToLuaStack<'a> {
|
|
|
|
unsafe fn push_to_lua_stack(&self, state: &'a State) -> Result<()>;
|
2024-01-22 03:53:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub trait FromLuaStack<'a>: Sized {
|
|
|
|
unsafe fn from_lua_stack(state: &'a State) -> Result<Self>;
|
|
|
|
}
|
|
|
|
|
2024-01-27 19:54:11 +00:00
|
|
|
impl<'a> PushToLuaStack<'a> for () {
|
|
|
|
unsafe fn push_to_lua_stack(&self, _state: &'a State) -> Result<()> {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-28 16:26:30 +00:00
|
|
|
impl<'a, T: PushToLuaStack<'a>> PushToLuaStack<'a> for Option<T> {
|
|
|
|
unsafe fn push_to_lua_stack(&self, state: &'a State) -> Result<()> {
|
|
|
|
if let Some(v) = self {
|
|
|
|
v.push_to_lua_stack(state)?;
|
|
|
|
} else {
|
|
|
|
unsafe {
|
|
|
|
lua::lua_pushnil(state.state_ptr());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-22 03:53:53 +00:00
|
|
|
/// Implements PushToLuaStack for a number
|
2024-01-26 20:43:26 +00:00
|
|
|
macro_rules! impl_as_lua_number {
|
2024-01-22 03:53:53 +00:00
|
|
|
($ty: ident) => {
|
2024-01-26 20:43:26 +00:00
|
|
|
impl<'a> AsLua<'a> for $ty {
|
|
|
|
fn as_lua(&self, _lua: &'a State) -> crate::Result<Value<'a>> {
|
|
|
|
Ok(Value::Number(*self as f64))
|
2024-01-22 03:53:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-27 19:54:11 +00:00
|
|
|
impl<'a> FromLua<'a> for $ty {
|
2024-01-26 20:43:26 +00:00
|
|
|
fn from_lua(_lua: &State, val: Value) -> crate::Result<Self> {
|
|
|
|
match val {
|
|
|
|
Value::Number(v) => Ok(v as $ty),
|
|
|
|
_ => {
|
|
|
|
Err(Error::UnexpectedType("Number".to_string(), val.type_name().to_string()))
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-01-22 03:53:53 +00:00
|
|
|
|
2024-01-26 20:43:26 +00:00
|
|
|
impl<'a> PushToLuaStack<'a> for $ty {
|
|
|
|
unsafe fn push_to_lua_stack(&self, state: &'a State) -> crate::Result<()> {
|
|
|
|
let v = self.as_lua(state)?;
|
|
|
|
v.push_to_lua_stack(state)
|
|
|
|
}
|
2024-01-22 03:53:53 +00:00
|
|
|
}
|
2024-01-26 20:43:26 +00:00
|
|
|
|
|
|
|
};
|
2024-01-22 03:53:53 +00:00
|
|
|
}
|
|
|
|
|
2024-01-26 20:43:26 +00:00
|
|
|
impl_as_lua_number!(i8);
|
|
|
|
impl_as_lua_number!(i16);
|
|
|
|
impl_as_lua_number!(i32);
|
|
|
|
impl_as_lua_number!(i64);
|
2024-01-22 03:53:53 +00:00
|
|
|
|
2024-01-26 20:43:26 +00:00
|
|
|
impl_as_lua_number!(u8);
|
|
|
|
impl_as_lua_number!(u16);
|
|
|
|
impl_as_lua_number!(u32);
|
|
|
|
impl_as_lua_number!(u64);
|
2024-01-22 03:53:53 +00:00
|
|
|
|
2024-01-26 20:43:26 +00:00
|
|
|
impl_as_lua_number!(f32);
|
|
|
|
impl_as_lua_number!(f64);
|
2024-01-22 03:53:53 +00:00
|
|
|
|
2024-01-26 20:43:26 +00:00
|
|
|
impl<'a> PushToLuaStack<'a> for String {
|
2024-01-22 03:53:53 +00:00
|
|
|
unsafe fn push_to_lua_stack(&self, state: &State) -> Result<()> {
|
|
|
|
state.ensure_stack(1)?;
|
|
|
|
|
|
|
|
let s = format!("{}\0", self);
|
|
|
|
let cstr = s.as_ptr() as *const i8;
|
|
|
|
lua::lua_pushstring(state.state_ptr(), cstr);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-27 19:54:11 +00:00
|
|
|
impl<'a> FromLua<'a> for String {
|
|
|
|
fn from_lua(_lua: &State, val: Value) -> crate::Result<Self> {
|
|
|
|
val.as_string().cloned()
|
|
|
|
}
|
2024-01-26 20:43:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> PushToLuaStack<'a> for &str {
|
2024-01-22 03:53:53 +00:00
|
|
|
unsafe fn push_to_lua_stack(&self, state: &State) -> Result<()> {
|
|
|
|
state.ensure_stack(1)?;
|
|
|
|
|
|
|
|
let s = format!("{}\0", self);
|
|
|
|
let cstr = s.as_ptr() as *const i8;
|
|
|
|
lua::lua_pushstring(state.state_ptr(), cstr);
|
|
|
|
|
2024-01-26 20:43:26 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-29 01:02:12 +00:00
|
|
|
#[allow(dead_code)]
|
2024-01-28 16:26:30 +00:00
|
|
|
pub struct Vec3 {
|
|
|
|
x: f32,
|
|
|
|
y: f32,
|
|
|
|
z: f32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Userdata for Vec3 {
|
2024-01-29 01:02:12 +00:00
|
|
|
fn build<'a>(_builder: &mut UserdataBuilder<'a, Self>) -> crate::Result<()> {
|
2024-01-28 16:26:30 +00:00
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn name() -> String {
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-26 20:43:26 +00:00
|
|
|
pub struct Vec2 {
|
|
|
|
x: f32,
|
|
|
|
y: f32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Userdata for Vec2 {
|
2024-01-28 16:26:30 +00:00
|
|
|
|
2024-01-26 20:43:26 +00:00
|
|
|
fn build<'a>(builder: &mut UserdataBuilder<'a, Vec2>) -> crate::Result<()> {
|
2024-01-28 16:26:30 +00:00
|
|
|
builder
|
2024-01-26 20:43:26 +00:00
|
|
|
.field_getter("x", |_, this| Ok(this.x))
|
2024-01-27 19:54:11 +00:00
|
|
|
.field_getter("y", |_, this| Ok(this.y))
|
|
|
|
|
|
|
|
.field_setter("x", |_, this, x: f32| this.x = x)
|
|
|
|
.field_setter("y", |_, this, y: f32| this.y = y)
|
|
|
|
|
|
|
|
.function("new", |lua, (x, y)| {
|
2024-01-29 01:02:12 +00:00
|
|
|
lua.create_userdata(Vec2 { x, y, })
|
2024-01-27 19:54:11 +00:00
|
|
|
})
|
2024-01-27 20:53:34 +00:00
|
|
|
|
|
|
|
// method test
|
2024-01-28 16:26:30 +00:00
|
|
|
.method("add", |lua, lhs: &Vec2, (rhs,): (&Vec3,)| {
|
2024-01-27 20:53:34 +00:00
|
|
|
let lx = lhs.x;
|
|
|
|
let ly = lhs.y;
|
|
|
|
|
|
|
|
let rx = rhs.x;
|
|
|
|
let ry = rhs.y;
|
|
|
|
|
2024-01-29 01:02:12 +00:00
|
|
|
lua.create_userdata(Vec2 { x: lx + rx, y: ly + ry, })
|
2024-01-27 20:53:34 +00:00
|
|
|
})
|
|
|
|
|
2024-01-27 19:54:11 +00:00
|
|
|
.meta_method(MetaMethod::Add, |lua, lhs: &Vec2, (rhs,): (&Vec2,)| {
|
|
|
|
let lx = lhs.x;
|
|
|
|
let ly = lhs.y;
|
|
|
|
|
|
|
|
let rx = rhs.x;
|
|
|
|
let ry = rhs.y;
|
|
|
|
|
2024-01-29 01:02:12 +00:00
|
|
|
lua.create_userdata(Vec2 { x: lx + rx, y: ly + ry, })
|
2024-01-27 19:54:11 +00:00
|
|
|
});
|
2024-01-26 20:43:26 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2024-01-28 16:26:30 +00:00
|
|
|
|
|
|
|
fn name() -> String {
|
|
|
|
"Vec2".to_string()
|
|
|
|
}
|
2024-01-26 20:43:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct UserdataProxy<T: Userdata>(PhantomData<T>);
|
|
|
|
|
|
|
|
impl<T: Userdata> UserdataProxy<T> {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
Self(PhantomData)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, T: Userdata> AsLua<'a> for UserdataProxy<T> {
|
2024-01-27 19:54:11 +00:00
|
|
|
fn as_lua(&self, _lua: &'a State) -> crate::Result<Value<'a>> {
|
2024-01-26 20:43:26 +00:00
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: Userdata> Userdata for UserdataProxy<T> {
|
|
|
|
fn build<'a>(builder: &mut UserdataBuilder<'a, Self>) -> crate::Result<()> {
|
|
|
|
|
|
|
|
let mut other = UserdataBuilder::<T>::new();
|
|
|
|
T::build(&mut other)?;
|
|
|
|
|
2024-01-27 20:53:34 +00:00
|
|
|
// only the functions need to be added since they're the only thing usable from a proxy
|
|
|
|
builder.functions = other.functions;
|
2024-01-26 20:43:26 +00:00
|
|
|
|
2024-01-22 03:53:53 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
2024-01-28 16:26:30 +00:00
|
|
|
|
|
|
|
fn name() -> String {
|
|
|
|
let name = format!("{}Proxy", T::name());
|
|
|
|
name
|
|
|
|
}
|
2024-01-22 03:53:53 +00:00
|
|
|
}
|