scScript Language
Except for pointer manipulation, types, and records, scScript has all the operators and control structures expected by C programmers, plus a few script-specific ones (highlighted below). Programming in scScript should be quite natural for C programmers... and for everyone else, C is a fantastic language to learn, especially easy without pointers and types (not to mention without the C++ object nonsense and syntax overloading)!
| Arithmetic and Logic | |
|---|---|
| A + B | Add |
| A - B | Subtract |
| A * B | Multiply |
| A / B | Divide |
| A % B | Modulo (remainder) |
| A & B | Bit and |
| A ^ B | Bit xor |
| ~ A | Bit invert |
| A && B | Logical and |
| A || B | Logical Or |
| ! A | Logical negate |
| A << B | Shift left |
| A >> B | Shift right |
| Assignment | |
|---|---|
| A = B | Simple assignment |
| A += B | A = A + B |
| A -= B | A = A - B |
| A *= B | A = A * B |
| A /= B | A = A / B |
| A %= B | A = A % B |
| A &= B | A = A & B |
| A |= B | A = A | B |
| A ^= B | A = A ^ B |
| A <<= B | A = A << B |
| A >>= B | A = A >> B |
| A =& B | A becomes B |
| Comparison | |
|---|---|
| A == B | Equal |
| A != B | Not equal |
| A < B | Less than |
| A <= B | Less than or equal |
| A > B | Greater than |
| A >= B | Greater than or equal |
| A === B | Identical (same storage) |
| A !== B | Not identical |
| Accessors, Constructors, and Definition | |
|---|---|
| Pkg.Func(...)(...) | Call function in pre-defined Pkg. (Can also call func stashed in Dict!) |
| MyDict.Key | Access dict entry where “Key” must be a string. (E.g. to use “Friday” as a key, use MyDict.Friday) |
| MyDict[Field] | Access dict entry where Field is interpreted. MyDict[14], MyDict[MyVar], or MyDict[“Friday”] (the last is same as MyDict.Friday) |
| MyArr[Index] | Access array entry. Index is interpreted and must have integer value. |
| Array(N) | Constructs new empty array. Uses default minimum if N is 0. |
| [A, B, C, ...] | Array constructor where A, B, and C values are interpreted. Arr[0] will get the value of A, Arr[1] will get B... |
| Dict(N) | Constructs new empty dict, sized for N entries. Uses default minimum size if N is 0. |
| [K1:A, K2:B, ...] | Dict constructor where keys and values are interpreted. |
| @A | Unpacks A into in or out list of a function call.
(Advanced operation!) All functions accept a variable number of args! Sys.GetArgs extracts full in/out arg lists. |
| Var | Declares variables, which can also be initialized in place. |
| Def | Defines new names (Starting with '#') for Int, Flt, or String values. |
| Function | Declare/Define functions. (Has 2 syntactic forms! *****) |
*****
Function MyFunc(InArgs...)(OutArgs...) {...}
is the
preferred form of function declaration. In the case of sub-functions
(nested declaration) the scope is hoisted to the very top container
function. Therefore, the container and any other sub-functions can
simply call it.
Var OtherFunc = Function(InArgs...)(OutArgs...) {...};
is
the second form. Here it first declares a variable, then stores a
nameless (lambda) function in it; but the var may be declared
separately, and assigned later. If declared within a function, this
form creates a normal local variable with a standard scope. The variable name will not
be hoisted to the top of its container function and may not be
visible to some sub-functions. (OtherFunc will be a global
if declared at the top level!)
Function MyFunc;
(no in/out list) can be used
to pre-declare MyFunc, so code calling it (perhaps for
mutual recursion) can be written before the function itself is properly
defined.
| Control Flow | |
|---|---|
| If and If/Else | C style conditionals and nested conditionals are supported. |
| While | C style While loop, supports Break and Continue. |
| Do While | C style Do-While loop, supports Break and Continue. |
| For | C style For loop, supports Break and Continue. |
| MapI MapK | MapI will iterate over all cells of an array or dict. MapK will iterate over all elts (non-empty cells) of an array or dict. Both support Break and Continue. |
| Goto | Goto is supported with standard limitations in scope and target. |
| Switch | C style Switch selector, supports Default case and Break. |
| Return Return Val Return Val OutOf RC |
Works with/without value, but can also Return OutOf RC (RunContext). Given RC of a caller, can return (non-local) directly from its caller! |
| Submit | Any function can Submit() to become a persistent coroutine. Submit returns an RC to caller. |
| Yield Yield Val Yield Val OutOf RC |
Coroutine can Yield to return a value to its caller. Also works with OutOf for non-local Yield. |
| Resume | Caller can Resume(RC) a coroutine after it does Yield or Submit(). |
| Release | Caller can Release(RC) to terminate a coroutine. |
| Debug | Call in Script to jump into debugger, uses raise(SIGINT). |