0
0

command definition interface

This commit is contained in:
DrMaxNix 2022-09-28 16:21:36 +02:00
parent f64f68a4e0
commit b6f1f1b97f
4 changed files with 43 additions and 0 deletions

View File

@ -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
View 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
View File

@ -0,0 +1,7 @@
Juicescript.command_add({
name: "mov",
alias: ["move", "set"],
function: function(runner){
/**/runner.debug("mov");
}
});

View File

@ -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;
}
}
}