Adding a Lisp variable to the extensions.ino


#1

I am trying to add a *platform* variable to my extensions file to differentiate between the PicoCalc and the T-Deck, e.g.:

> *platform*
:picocalc

The closest example I could find in the source is *features*, but that appears to call features() in eval. Is there a way I’m missing to do this?


#2

To achieve what you want you could define *platform* in a Lisp Library at the start of your source:

const char LispLibrary[] PROGMEM = R"lisplibrary(

(defvar *platform* ':picocalc)

)lisplibrary";

To make this definition load at startup you would also uncomment:

#define lisplibrary

For more information see Lisp Library.


#3

This is what I’m doing now; I’m working on three platforms right now and trying to keep the LispLibrary and extensions sync’d between them. The extensions file is a attractive because the ifdef guards make it easier to customize per-platform.

I think the better answer is maybe to just make it a nullary function (platform) and not have it be a variable.


#4

I’ll respond in this thread since it’s more relevant. What you can do is add a c function to extensions.ino that returns the symbol of the platform you’re using. You can #ifdef the different strings from the c code for different platforms. Unfortunately I don’t have any way to test this code at the moment but it would be like

object *fn_platform (object *args, object *env) {
  (void) env;
  #ifdef PICOCALC
   return lispstring(":picocalc");
  #else if def T-DECK
    return lispstring(":t-deck");
  #else
    //Other stuff
  #endif
}

That’s not actual code, you’d have to figure out the details there but I hope it shows you the idea. You can see here how to fully add c functions to extensions.ino http://www.ulisp.com/show?19Q4


#5

This is what I’m doing now, I was just hoping to have a variable instead of a function.


#6

I’m honestly not sure if there is an obvious way to add such variables unless I’m missing something. It’s possibly worth figuring out, but also calling functions isn’t the worst thing


#7

platform_s

That’s what I ended up doing. There’s too many other things I want to do rather than figure it out right now.