Class Class
- All Implemented Interfaces:
Proxy
JSCContext.
It allows to create new JavaScripts objects whose instances are created by the user using
this API.
It's possible to add constructors, properties and methods for a JSSClass by providing
GCallbacks to implement them.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classClass.Builder<B extends Class.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static classNested classes/interfaces inherited from class GObject
GObject.NotifyCallback, GObject.ObjectClass -
Constructor Summary
ConstructorsConstructorDescriptionClass()Create a new Class.Class(MemorySegment address) Create a Class instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionaddConstructor(@Nullable String name, @Nullable Callback callback, Type returnType, @Nullable Type @Nullable [] parameterTypes) Add a constructor tojscClass.Ifnameisnull, the class name will be used.addConstructorVariadic(@Nullable String name, @Nullable Callback callback, Type returnType) Add a constructor tojscClass.Ifnameisnull, the class name will be used.voidaddMethod(String name, @Nullable Callback callback, Type returnType, @Nullable Type @Nullable [] parameterTypes) Add method withnametojscClass.When the method is called by JavaScript or jsc_value_object_invoke_method(),callbackis called receiving the class instance as first parameter, followed by the method parameters and thenuserDataas last parameter.voidaddMethodVariadic(String name, @Nullable Callback callback, Type returnType) Add method withnametojscClass.When the method is called by JavaScript or jsc_value_object_invoke_method(),callbackis called receiving the class instance as first parameter, followed by aGPtrArrayofJSCValues with the method arguments and thenuserDataas last parameter.voidaddProperty(String name, Type propertyType, @Nullable Callback getter, @Nullable Callback setter) Add a property withnametojscClass.When the property value is read,getteris called receiving the the class instance as first parameter anduserDataas last parameter.protected ClassasParent()Return this instance as if it were its parent type.static Class.Builder<? extends Class.Builder> builder()AClass.Builderobject constructs aClasswith the specified properties.static MemoryLayoutThe memory layout of the native struct.getName()Get the class name of this ClassGet the parent class of this Classstatic @Nullable TypegetType()Get the GType of the Class class.Methods inherited from class GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newv, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withPropertiesMethods inherited from class TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Class
Create a Class instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
Class
public Class()Create a new Class.
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
-
addConstructorVariadic
public Value addConstructorVariadic(@Nullable String name, @Nullable Callback callback, Type returnType) Add a constructor to
jscClass.Ifnameisnull, the class name will be used. Whennew is used with the constructor or jsc_value_constructor_call() is called,callbackis invoked receiving aGPtrArrayofJSCValues as arguments anduserDataas the last parameter. When the constructor object is cleared in theJSCClasscontext,destroyNotifyis called withuserDataas parameter.This function creates the constructor, which needs to be added to an object as a property to be able to use it. Use jsc_context_set_value() to make the constructor available in the global object.
Note that the value returned by
callbackis adopted byjscClass,and theGDestroyNotifypassed to jsc_context_register_class() is responsible for disposing of it.- Parameters:
name- the constructor name ornullcallback- aGCallbackto be called to create an instance of this ClassreturnType- theGTypeof the constructor return value- Returns:
- a
JSCValuerepresenting the class constructor.
-
addConstructor
public Value addConstructor(@Nullable String name, @Nullable Callback callback, Type returnType, @Nullable Type @Nullable [] parameterTypes) Add a constructor to
jscClass.Ifnameisnull, the class name will be used. Whennew is used with the constructor or jsc_value_constructor_call() is called,callbackis invoked receiving the parameters anduserDataas the last parameter. When the constructor object is cleared in theJSCClasscontext,destroyNotifyis called withuserDataas parameter.This function creates the constructor, which needs to be added to an object as a property to be able to use it. Use jsc_context_set_value() to make the constructor available in the global object.
Note that the value returned by
callbackis adopted byjscClass,and theGDestroyNotifypassed to jsc_context_register_class() is responsible for disposing of it.- Parameters:
name- the constructor name ornullcallback- aGCallbackto be called to create an instance of this ClassreturnType- theGTypeof the constructor return valueparameterTypes- a list ofGTypes, one for each parameter, ornull- Returns:
- a
JSCValuerepresenting the class constructor.
-
addMethodVariadic
Add method with
nametojscClass.When the method is called by JavaScript or jsc_value_object_invoke_method(),callbackis called receiving the class instance as first parameter, followed by aGPtrArrayofJSCValues with the method arguments and thenuserDataas last parameter. When the method is cleared in theJSCClasscontext,destroyNotifyis called withuserDataas parameter.Note that the value returned by
callbackmust be transfer full. In case of non-refcounted boxed types, you should useG_TYPE_POINTERinstead of the actual boxedGTypeto ensure that the instance owned byJSCClassis used. If you really want to return a new copy of the boxed type, useJSC_TYPE_VALUEand return aJSCValuecreated with jsc_value_new_object() that receives the copy as the instance parameter.- Parameters:
name- the method namecallback- aGCallbackto be called to invoke methodnameof this ClassreturnType- theGTypeof the method return value, orG_TYPE_NONEif the method is void.
-
addMethod
public void addMethod(String name, @Nullable Callback callback, Type returnType, @Nullable Type @Nullable [] parameterTypes) Add method with
nametojscClass.When the method is called by JavaScript or jsc_value_object_invoke_method(),callbackis called receiving the class instance as first parameter, followed by the method parameters and thenuserDataas last parameter. When the method is cleared in theJSCClasscontext,destroyNotifyis called withuserDataas parameter.Note that the value returned by
callbackmust be transfer full. In case of non-refcounted boxed types, you should useG_TYPE_POINTERinstead of the actual boxedGTypeto ensure that the instance owned byJSCClassis used. If you really want to return a new copy of the boxed type, useJSC_TYPE_VALUEand return aJSCValuecreated with jsc_value_new_object() that receives the copy as the instance parameter.- Parameters:
name- the method namecallback- aGCallbackto be called to invoke methodnameof this ClassreturnType- theGTypeof the method return value, orG_TYPE_NONEif the method is void.parameterTypes- a list ofGTypes, one for each parameter, ornull
-
addProperty
public void addProperty(String name, Type propertyType, @Nullable Callback getter, @Nullable Callback setter) Add a property with
nametojscClass.When the property value is read,getteris called receiving the the class instance as first parameter anduserDataas last parameter. When the property value needs to be set,setteris called receiving the the class instance as first parameter, followed by the value to be set and thenuserDataas the last parameter. When the property is cleared in theJSCClasscontext,destroyNotifyis called withuserDataas parameter.Note that the value returned by
gettermust be transfer full. In case of non-refcounted boxed types, you should useG_TYPE_POINTERinstead of the actual boxedGTypeto ensure that the instance owned byJSCClassis used. If you really want to return a new copy of the boxed type, useJSC_TYPE_VALUEand return aJSCValuecreated with jsc_value_new_object() that receives the copy as the instance parameter.- Parameters:
name- the property namepropertyType- theGTypeof the property valuegetter- aGCallbackto be called to get the property valuesetter- aGCallbackto be called to set the property value
-
getName
-
getParent
-
builder
AClass.Builderobject constructs aClasswith the specified properties. Use the variousset...()methods to set properties, and finish construction withClass.Builder.build().- Returns:
- the builder object
-