Sharing Code Between Programs
|
01-16-2022, 08:44 PM
(This post was last modified: 01-16-2022 08:53 PM by IHarwell.)
Post: #1
|
|||
|
|||
Sharing Code Between Programs
I can't be the only person annoyed that the documentation for the Prime describes "calling programs from other programs" basically amounts to "there's a call stack, but you can't call functions from other files."
With that said, I found a rather straightforward way to call code contained in other files. I haven't tested the feature too extensively, but here's what I've found so far: Let's say you want to make a function library for your programs to share. In my case, I wanted to have a way to draw the "shift" symbol in the correct place for any of my programs. This is the "library" file I created. Code: #cas This file creates the functions and makes them available through the CAS system. To call them, there are two options that currently occur to me. The first is more direct, and looks like: Code: CAS("DrawShiftMark()"); The second basically uses a verbose import statement by wrapping the CAS command in a function. Code: LOCAL DrawShiftMark() While it's a workable solution as-is, this approach is vulnerable to name collisions. I'll look into using the "folders" system that I ran across and posted about in an earlier thread to see if I can get something like namespaces working. Until then, I thought it was a pretty neat technique that enables more compact programs than could be done otherwise. If anyone has related ideas or has any ways to extend this, I'd be very interested to take a look. P.S. The current holdup for implementing namespaces is due to the EVAL function doing weird things with the "END" keyword. There may be a workaround, but I'll have to test it out a bit. |
|||
01-16-2022, 10:15 PM
Post: #2
|
|||
|
|||
RE: Sharing Code Between Programs
Any reason to have these defined as CAS programs while they don’t use any CAS function?
I would rather define them as PPL programs and with EXPORT they would be callable from other programs : Code: #pragma mode( separator(.,;) integer(h32) ) |
|||
01-16-2022, 10:44 PM
Post: #3
|
|||
|
|||
RE: Sharing Code Between Programs
(01-16-2022 10:15 PM)Didier Lachieze Wrote: Any reason to have these defined as CAS programs while they don’t use any CAS function? Weirdly, I was getting errors with that method. Ideally, I'd like to arrange these as "UI.DrawShift" and "UI.ClearShift". Unfortunately, that requires CAS to do. Getting it to work is proving challenging. They appear to have gone to great lengths to prevent the use of those structures in code. |
|||
01-19-2022, 12:29 AM
Post: #4
|
|||
|
|||
RE: Sharing Code Between Programs
Have you tried attaching the code to an app and calling that?
Which I think you can do by calling Code: var := appname.functioname(params) Sorry to be so vague - don't have the Prime to hand but I'm sure I recall CdB mentioning it at one time. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)