pub struct pxs_PixelObject {
pub type_name: String,
pub ptr: *mut c_void,
pub lang_ptr: Mutex<*mut c_void>,
pub free_lang_ptr: Mutex<bool>,
pub free_method: FreeMethod,
pub callbacks: Vec<ModuleCallback>,
}Expand description
A PixelScript Object.
The way this works is via the host, a Pseudo type can be created. So when the scripting language interacts with the object, it calls it’s pseudo methods.
example:
struct Person {
const char* name;
int age;
Person(const char* name, int age) {
this->name = name;
this->age = age;
}
void set_name(const char* name) {
this->name = name;
}
void set_age(int age) {
this->age = age;
}
int get_age() {
return this->age;
}
const char* get_name() {
return this->name;
}
};
void free_person(void* p) {
// TODO
}
Var* person_set_name(int argc, Var** argv, void* opaque) {
Var* object = argv[0];
Person* p = object.value.object_val as Person;
Var* name = argv[1];
p->set_name(name.value.string_val);
return NULL;
}
Var* new_person(int argc, Var** argv, void* opaque) {
Person* p = malloc();
PixelObject* object_ptr = pixelscript_new_object(p, free_person);
pixelscript_object_add_callback(object_ptr, "set_name", person_set_name);
return pixelscript_var_object(object_ptr);
}
// OOP base
pixelscript_add_object("Person", new_person);
// Or functional
pixelscript_add_callback("new_person", new_person);In a JS example:
let p = new Person("Jordan");
p.set_name("James");This is why a Objects are more like Pseudo types than actual class/objects.
Fields§
§type_name: StringType name (this is a hash)
ptr: *mut c_voidThe Host pointer
lang_ptr: Mutex<*mut c_void>The language object pointer.
free_lang_ptr: Mutex<bool>Should the lang_ptr be freed by PixelScript?
free_method: FreeMethodThe Method for freeing
callbacks: Vec<ModuleCallback>Callbacks with names.
Important to note that a PixelObject can not have static callbacks.
The first Var will always be the ptr.
Implementations§
Source§impl pxs_PixelObject
impl pxs_PixelObject
pub fn new(ptr: *mut c_void, free_method: FreeMethod, type_name: &str) -> Self
pub fn add_callback(&mut self, name: &str, full_name: &str, idx: i32)
pub fn update_lang_ptr(&self, n_ptr: *mut c_void)
pub fn update_free_lang_ptr(&self, val: bool)
Trait Implementations§
Source§impl Drop for pxs_PixelObject
impl Drop for pxs_PixelObject
Source§impl PtrMagic for pxs_PixelObject
impl PtrMagic for pxs_PixelObject
Source§fn into_raw(self) -> *mut Self
fn into_raw(self) -> *mut Self
Moves the object to the heap and returns a raw pointer.
Caller owns this memory but don’t worry about freeing it. The library frees it somewhere.
Source§unsafe fn from_borrow<'a>(ptr: *mut Self) -> &'a mut Self
unsafe fn from_borrow<'a>(ptr: *mut Self) -> &'a mut Self
Build from a Ptr but only get a reference, this means that the caller will still own the memory
impl Send for pxs_PixelObject
impl Sync for pxs_PixelObject
Auto Trait Implementations§
impl !Freeze for pxs_PixelObject
impl RefUnwindSafe for pxs_PixelObject
impl Unpin for pxs_PixelObject
impl UnwindSafe for pxs_PixelObject
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more