Skip to content

MoonLiveScript

Source: MoonLiveScript.h

MoonLiveScript

class MoonLiveScript
src/light/moonlive/MoonLiveScript.h:27

One scripted module's script: the file it names, the compiled program, and the content hash.

The rule it exists to state once: if the file changed, recompile. That is all [sync()] is.

Public Methods

inline void setPoolSizer(PoolSizeFn fn, void * ctx) : Let a binding that owns a particle pool size it from the script's defineControls().

inline void setTrailSizer(TrailSizeFn fn, void * ctx) : The same for a trail plane, which only a script asking with trail(1) pays for.

inline bool sync(const SysVarTable & sysvars, MoonModule & owner, const BuiltinTable & builtins = lightBuiltins()) : Re-read the file and recompile when its content hash moved.

inline char * buffer() : The name buffer the script control binds to.

inline size_t bufferSize() const : How many bytes the name buffer holds.

inline const char * name() const : The script file this module runs.

inline void setName(const char * n) : Point at a different script. The next [sync()] compiles it.

inline Dim dimensions() const : The dimensionality the script declared, or D2 when it declared none.

inline const char * tags() const : The emoji the script declared, or null when it declared none.

inline void releaseReporting(MoonModule & owner) : Hand back what this script reported, called after the engine is freed.

inline void invalidate() : Forget what is compiled, so the next sync rebuilds for a module coming back from disabled.

inline void publishDeclaredControls(ControlList & controls) : Publish every control the script declared, bound by reference to its live arena slot.

inline MoonLive & engine() : The engine holding the compiled program.

inline const MoonLive & engine() const : The engine holding the compiled program, for a reader.

inline bool ok() const : Whether a program is compiled and ready to run.

Public Static Attributes

constexpr size_t kMaxStatus = 112 : The longest status this module reports, with its offset suffix.

constexpr const char * kShadowMark = "edited copy" : What the status says when the user's copy is hiding a shipped one.

constexpr const char * kStaleMark = "edited copy, shipped one updated" : Said instead when the shipped copy has moved on since the fork.

More info

Held by value

The three scripted modules derive from three sibling bases under MoonModule. A shared base would need virtual inheritance and change the layout of every module.

One answer to one question

The three bindings each grew their own bookkeeping around that rule and drifted apart. An effect had no content hash, so editing a script changed nothing until it was renamed. A layout cleared its hash only on a name change, and only a modifier re-read the file.