Skip to content

Commit

Permalink
feat: allowed injiza_amakuru() to have multiple args (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
pacifiquem authored Mar 12, 2024
1 parent cf4bd70 commit 46a5733
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/runtime/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
ObjectVal,
} from './values';
import Environment from './environment';
import { printValues } from './print';
import { makeValues, printValues } from './print';
import moment from 'moment';
import {
readFileSync,
Expand Down Expand Up @@ -75,7 +75,7 @@ export function createGlobalEnv(filename: string): Environment {
const MIN_ARGS_LENGTH = 1;
if (args.length < MIN_ARGS_LENGTH)
LogError('injiza_amakuru expects at least one argument');
const cmd = (args[0] as StringVal).value;
const cmd = makeValues(args).value;

try {
const result = prompt()(cmd);
Expand Down
11 changes: 11 additions & 0 deletions src/runtime/print.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
BooleanVal,
ObjectVal,
FunctionValue,
MK_STRING,
} from './values';

import { LogMessage } from '../lib/log';
Expand All @@ -23,6 +24,16 @@ export function printValues(args: Array<RuntimeVal>) {
LogMessage(output);
}

// Utility for injiza_amakuru(), helps injiza_amakuru() to have multiple arguments
export function makeValues(args: Array<RuntimeVal>) {
let output = '';
for (let i = 0; i < args.length; i++) {
const arg = args[i];
output += matchType(arg);
}
return MK_STRING(output);
}

export function matchType(arg: RuntimeVal) {
switch (arg.type) {
case 'string':
Expand Down

0 comments on commit 46a5733

Please sign in to comment.