-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
91 changed files
with
10,842 additions
and
4,221 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
let extension = lavendeux.extend({ | ||
'name': 'simple_extension', | ||
'author': '@rscarson', | ||
'version': '1.0.0' | ||
}); | ||
|
||
extension.addFunction('add', (left, right) => left + right, 'Float') | ||
.requireArgument('Integer').requireArgument('Integer'); | ||
|
||
extension.addDecorator('usd', (input) => `${input}`, 'Float') | ||
|
||
lavendeux.register(extension); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,19 @@ | ||
/** | ||
* This function tells Lavendeux about this extension. | ||
* It must return an object similar to the one below. | ||
* @returns Object | ||
*/ | ||
function extension() { | ||
return { | ||
name: "Stateful function demo", | ||
author: "@rscarson", | ||
version: "0.2.0", | ||
let extension = lavendeux.extend({ | ||
'name': 'stateful_extension', | ||
'author': '@rscarson', | ||
'version': '1.0.0' | ||
}); | ||
|
||
functions: { | ||
"set": "functionSet" | ||
}, | ||
}; | ||
} | ||
|
||
/** | ||
* Functions can also be stateful, gaining access to the parser's variables | ||
* @param {Value} args | ||
* @returns {Value} result | ||
*/ | ||
function functionSet(args) { | ||
if (args.length != 2) { | ||
throw new Error("set(<string>, <any>): expected 2 arguments"); | ||
} else if (!args[0].String) { | ||
throw "set(<string>, <any>): expected a string value"; | ||
} | ||
|
||
let name = args[0].String, value = args[1]; | ||
const state = getState(); | ||
extension.addFunction('put', (name, value, state) => { | ||
state[name] = value; | ||
setState(state); | ||
|
||
return value; | ||
} | ||
}) | ||
.requireArgument('String') | ||
.requireArgument(); | ||
|
||
extension.addFunction('get', (name, state) => { | ||
return state[name]; | ||
}) | ||
.requireArgument('String'); | ||
|
||
lavendeux.register(extension); |
Oops, something went wrong.