From 2574ad297b54ddf018c99ffb94917901517a87b5 Mon Sep 17 00:00:00 2001 From: Quentin Leonetti Date: Sat, 20 Jul 2019 19:46:52 +0200 Subject: [PATCH] add suport for {} objects --- desktop/sources/scripts/library.js | 8 ++++++++ desktop/sources/scripts/lisp.js | 27 +++++++++++++++++++++------ examples/objects.lisp | 11 +++++++++++ 3 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 examples/objects.lisp diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js index e0a5ea4..0a8aa78 100644 --- a/desktop/sources/scripts/library.js +++ b/desktop/sources/scripts/library.js @@ -233,6 +233,14 @@ function Library (ronin) { }, h) } + this.keys = (item) => { // Returns a list of the object's keys + return Object.keys(item) + } + + this.values = (item) => { // Returns a list of the object's values + return Object.values(item) + } + // Frame this.frame = () => { // Returns a rect of the frame. diff --git a/desktop/sources/scripts/lisp.js b/desktop/sources/scripts/lisp.js index 4fd0f1e..3077df4 100644 --- a/desktop/sources/scripts/lisp.js +++ b/desktop/sources/scripts/lisp.js @@ -60,6 +60,12 @@ function Lisp (input, lib) { return interpret(input[2], new Context(lambdaScope, context)) } }, + if: async function (input, context) { + if (await interpret(input[1], context)) { + return interpret(input[2], context) + } + return input[3] ? interpret(input[3], context) : [] + }, __fn: function (input, context) { return async function () { const lambdaArguments = arguments @@ -70,11 +76,12 @@ function Lisp (input, lib) { return interpret(input.slice(1), new Context(lambdaScope, context)) } }, - if: async function (input, context) { - if (await interpret(input[1], context)) { - return interpret(input[2], context) + __obj: async function (input, context) { + const obj = {} + for (let i = 1 ; i