✨ command definition interface
This commit is contained in:
parent
f64f68a4e0
commit
b6f1f1b97f
@ -68,6 +68,13 @@
|
||||
echo("\n");
|
||||
}
|
||||
}
|
||||
|
||||
foreach(scandir("../src/command") as $one_file){
|
||||
if(is_file("../src/command/" . $one_file)){
|
||||
require("../src/command/" . $one_file);
|
||||
echo("\n");
|
||||
}
|
||||
}
|
||||
?></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
7
src/command/drw.js
Normal file
7
src/command/drw.js
Normal file
@ -0,0 +1,7 @@
|
||||
Juicescript.command_add({
|
||||
name: "drw",
|
||||
alias: ["draw", "echo"],
|
||||
function: function(runner){
|
||||
/**/runner.io.stdout("drw");
|
||||
}
|
||||
});
|
7
src/command/mov.js
Normal file
7
src/command/mov.js
Normal file
@ -0,0 +1,7 @@
|
||||
Juicescript.command_add({
|
||||
name: "mov",
|
||||
alias: ["move", "set"],
|
||||
function: function(runner){
|
||||
/**/runner.debug("mov");
|
||||
}
|
||||
});
|
22
src/main.js
22
src/main.js
@ -40,6 +40,11 @@ class Juicescript {
|
||||
|
||||
|
||||
|
||||
// COMMAND FUNCTIONS //
|
||||
static command = {};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
CONSTRUCTOR: Return new juicescript parser with OPTIONS
|
||||
*/
|
||||
@ -118,4 +123,21 @@ class Juicescript {
|
||||
// run the program
|
||||
runner.run();
|
||||
}
|
||||
|
||||
/*
|
||||
HELPER: Add command with expanded command aliases to command function list
|
||||
*/
|
||||
static command_add(command){
|
||||
for(var name_or_alias of command.alias.concat([command.name])){
|
||||
// MAKE SURE WE'RE NOT RE-DEFINING IT //
|
||||
if(Object.keys(Juicescript.command).includes(name_or_alias)){
|
||||
// throw error
|
||||
throw "cannot redefine command '" + name_or_alias + "'";
|
||||
}
|
||||
|
||||
|
||||
// ADD //
|
||||
Juicescript.command[name_or_alias] = command;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user