Lowerdash is an object-oriented extension to SmileBasic. It lets you write code very similar to C++, Java, or Javascript.
In this tutorial, I present a quick-overview of the high-level features and how they compare to other object-oriented languages.
Pointer
Lowerdash overloads the $ variable type to mean "pointer" rather than just "string". You store objects to variables post-fixed with $.
$ variables are passed by reference.
VAR myO$ = new myMod(42)
Objects
Objects in Lowerdash are like most objects: they can contain properties and functions.
A "singleton" object is equivalent to a
MODULE. Modules implicitly end at the end of a file, or can be closed with the
END keyword.
VARs inside a module will always be attached to the object.
DEFs are only attached to a module if they are declared
STATIC.
You can create a module by defining it in code:
MODULE myMod
VAR inner
STATIC DEF myFunc
PRINT _.inner
'doing stuff
END
END
Classes
In Lowerdash, Classes are just Modules with a function named "new". This makes it simpler to think about operations: All modules are objects, all instances are objects.
As mentioned, a Module that is used as a class must provide a
constructor. The constructor must be declared with
EXPORT.
EXPORT will add a
DEF to a special table that belongs to the current Module. This table contains the properties of a module that are only usable by instances. You can also add instance members (vars) to this table by using the
MEM keyword.
MODULE myMod
MEM member
EXPORT DEF new(arg)
me.member = arg
return me
END
END
Instances
Instances are constructed with the
new keyword, just like most languages.
Instances behave just like modules. Under the hood, they have some Lowerdash managed state. An instance behaves the same as the
MODULE that constructed it, but will also have access to anything that has been
EXPORTed from that module as well.
MODULE myMod
...
EXPORT DEF act
print "This is an action"
END
...
END
VAR o$ = new myMod(42)
o$.act
Scoping
Scopes are not truly recursive in SmileBasic like other languages. There only exists the global scope and the function scope.
In Lowerdash,
STATIC and
EXPORT DEFs have special properties added to their scopes:
STATIC:
-
_ - a placeholder for the current module.
EXPORT:
-
_ - a placeholder for the current module.
-
me - the calling object. equivalent to
this in most other languages (just shorter to type)
Examples
Java to Lowerdash
Suggest code for me to translate...
Javascript to Lowerdash
Suggest code for me to translate...
C++ to Lowerdash
Suggest code for me to translate...