Wiki

Clone wiki

PowerChat / Commands_classes

Classes and namespaces

copy expose namespace namespace-clear new new-class newinstance _sandbox

copy

Copies one or more commands or variables to a specified variable(s).

#!Haskell
!copy var1 var2        # Copies var1 to var2 and any var1.* to var2.*
!copy var1 var2 @      # Copies var1 to var2 and any var1@* to var2@*
!copy var1 var2 false  # Copies only var1 to var2

expose

Definition:

#!Haskell
!expose={!copy !1 common->!1}
Copies the set of variables with the name specified in argument 1 to 'common' namespace.
#!Haskell
!expose myvar

namespace

Switches current namespace to the one specified in argument 1. If called without arguments, switches to the default namespace.

#!Haskell
!namespace example

namespace-clear

Clears the namespace specified in argument 1. If that is a current namespace, it will become invisible for commands that specify its name and will be accessible until the namespace is switched.

#!Haskell
!namespace-clear example

new

Definition:

#!text
!new={[ # Set do and dont, then use isdef to decide which to run #
]    { {!new.{!2}.opt1:{!.1}} {!new.{!2}.opt2:{!.2}} } [
]    !new.do={ [
]        {!copy {!1} {!2} {!or {!3} .}} [ # Create 'object' #
]        {!{!2}{!or {!3} .}_parent:{!1}} [ # Set '_parent' #
]        {!{!2}{!or {!3} .}_parent_const {!{!if '{!or {!.2}}'=='' -or -new.opt1}}} [
]        {!{!2} !{!if '{!or {!.2}}'=='' -{new.{!2}.opt1} -{new.{!2}.opt2}}}} [ # Run object (constructor) #
]    {!new.dont={!print No such class: {!new.arg1}}} [
]    {!{!isdef {!1} -new.do -new.dont}}}
Creates a new object of a class by the name passed as argument 1 and saves it to the variable by the name passed as argument 2. If there is only one option, uses it as constructor arguments. If there are two options, uses option 1 as parent constructor arguments and option 2 as constructor arguments. Additional argument 3 can specify what separator the class uses, defaults to dot.
#!Haskell
!new class object -[arg1 arg2]

new-class

Definition:

#!Haskell
!new-class={[
]    {!new-class.do={ [
]        {!copy {!new-class.arg1} {!new-class.arg2} {!or {!new-class.arg3} .}} [
]        {!{!new-class.arg2}{!or {!new-class.arg3} .}_parent:{!new-class.arg1}}}} [
]    {!new-class.dont={!print No such class: {!new-class.arg1}}} [
]    {!{!isdef {!1} -new-class.do -new-class.dont}} [
]    {{!new-class.arg3={}}}}
Clones the class by the name passed as argument 1 and saves it to the variable by the name passed as argument 2. Then sets '_parent' field for the new class to contain the name of the original class. Additional argument 3 can specify what separator the class uses, defaults to dot.
#!Haskell
!new-class class1 class2

newinstance

Creates a subinstance of PowerChat that will use argument 1 as its control character. The subinstance will be used every time when its control character is present in the input string. There can be any number of such subinstances.

#!Haskell
!newinstance @

_sandbox

If set to 'true' then PowerChat will not look for variables in other namespaces (if the names of the variables do not specify the namespace explicitly), only in the current namespace and in the default namespace.

Updated