1 == Extending SCL environment ==
3 The SCL values, data types etc. that are available in expressions and commands are defined in SCL modules. Currently all SCL modules must be part of the product plugins (in the future, you can also write modules inside the models). Each module is identified by a URI.
5 SCL module is a text file ending with extension ".scl". The recommended place for modules is scl/ folder under plugin root, but also other directories can be used:
9 fib :: Integer -> Integer
11 | otherwise = fib (x-1) + fib (x-2)
15 A directory is declared as a SCL package with the following kind of extension points defined in org.simantics.scl.runtime:
17 <extension point="org.simantics.scl.runtime.package">
18 <package URI="http://www.simantics.org/Tests"
23 The module is not automatically available in the console, but you must run an import declaration:
25 > import "http://www.simantics.org/Tests/Test1" as Test1
30 Import declaration can also be used in modules to refer other modules. Cyclic module dependencies are not allowed.
32 == Importing functionality from Java ==
34 Java interfaces and classes can be imported from Java by declaring them inside importJava block:
36 importJava "java.util.regex.Pattern" where
39 importJava "java.util.List" where
43 Java methods, constructors and fields can be similarly imported by giving
44 their type annotations in importJava block:
46 importJava "java.util.regex.Pattern.compile" where
48 compilePattern :: String -> Pattern
51 createMatcher :: Pattern -> String -> <Proc> Matcher
53 importJava "java.util.regex.Matcher" where
57 matcherMatches :: Matcher -> <Proc> Boolean
59 matches : Pattern -> String -> <Proc> Boolean
60 matches pattern text = do
61 matcherMatches (createMatcher pattern text)
66 importJava "java.util.ArrayList" where
68 createArrayList :: () -> <Proc> List a
71 createArrayListWithCapacity :: Integer -> <Proc> List a
74 sizeList :: List a -> <Proc> Integer
77 getList :: List a -> Integer -> <Proc> a
80 setList :: List a -> Integer -> a -> <Proc> ()
83 addList :: List a -> a -> <Proc> Boolean
86 Java constructor is referred with "<init>". If Java method name and SCL name matches the annotation @JavaName can be left out. Java import mechanism tries to be quite flexible. It provides some arguments based on the effects the function has. It also ignores the return value of the Java method if return type is () in SCL.
88 A major functionality currently still missing is the ability to create new implementations of existing Java interfaces in SCL code or extend an existing class. This can be worked around currently by writing new implementations in Java.