Skip to content

4. Directories

Yazid Slila edited this page Feb 1, 2022 · 4 revisions

in DyeScript a directory is a map of keys and values that can be accessed from javascript files via dye object and .dye files

read/write directory

you can choose only one "main" directory to write values in and read values from at the same time.

open global
set a 5
set b 3
open local
set a 7
>> &a
>> &b
open global 
>> &a
>> &b

this script produces

>> 7
>> undefined
>> 5
>> 3

read-only directories

it is hard to open every single time a directory to use values specially if the values are already defined e.g. bluedye directory of predefined colors.

the solution is simple DyeScript offers you the possibility to open more than one directory in read-only mode.

open global
set a 5
set b 3
open local global bluedye
set a 7
>> &a
>> &b
>> &yellow
open global 
>> &a
>> &b

global and bluedye are opened in read-only mode

if some global and bluedye values share the same key names, the compiler always uses the value of the directory opened first.

this script produces

>> 7
>> 3
>> "#FFFF00"
>> 5
>> 3

default directories

every module (.dye file) has default and private directory created automatically

set a 3
>> &a
open global
>> &a
open default
set b &a
>> 3
>> 3

default directory is always active as the last read-only directory.

we can reopen default by simply using open default .

public directory

public directory is always accessible and shared by the DyeScript process and modules .

every key is unique and we cannot change values after the first assignment.

put h unchangeable
>> @h
put h i_do_not_think_so
>> unchangeable
>> error : public/h cannot be modified

public values

some values in public directory are dynamic

@FILE : current file name

@LINE : current line number

@SIZE : size of buffer

@RAND : random color | float

@TRIGGER : the module that used the current module

@DIR : current directory

Clone this wiki locally