ChaiScript: loading preprocessed script file from memory - chaiscript

In ChaiScript, there is a .use() function which takes a file path and loads the file and makes every function and variable available in the script. This is great functionality if you want a file from disk, however I'm looking to do the same but from a file which has been loaded, preprocessed as a string and stored in memory. So pretty much an equivalent to the .use function, taking a string representing the whole script instead of just a path.
Is this possible somehow?

I believe you simply want to call the eval function, like:
std::string previouslyLoadedString = loadFileAsString();
chai.eval(previouslyLoadedString);
https://github.com/ChaiScript/ChaiScript/blob/develop/cheatsheet.md#general-1

Related

in Batch:keep functions in the file they are used in, or keep functions in function-specific files

About a week ago I started making a small batch text/turn-based rpg.
Currently what I'm doing is putting all the functions that are used in a file in that file, i.e I have a file named 'Init.bat' I put all the display/logic/arithmetic/validation/variable-functions in it. What I'm wondering is.. would it be better to put the functions in their own file, i.e file for display/logic/etc, or continue what I'm doing now?
The only files that are 'working' are: Classes.bat,Init.bat,PlayerInfo.bat
https://github.com/Ravkrat/batchrpg/tree/fixingInit <-latest build
(hopefully its ok for me to link to GitHub.. the batch file is large now and don't want to make this post to long)
TL;DR
separate functions from the file they are used in and put them in function specific files,or keep functions in the file that uses them.

How do you constantly monitor the contents of a file in clojure?

I have an incanter dataset that I would like to re-load every time another processes changes the source csv file. In other words, the mydata_ incanter dataset should be current every time I look. How can I implement this in idiomatic clojure?
(use 'incanter.io)
(def mydata_ (read-csv "./changingfile.csv"))
At some point, another process changes changingfile.csv, how do make sure that mydata_ is updated automatically? This is a bit different from just adding a watch function to an existing data structure within clojure.
Thanks.
nice library for watching the file system here: https://github.com/derekchiang/Clojure-Watch
can be used to watch the csv and can set mydata_ as an atom, or whatever uses mydata can be kicked off from clojure-watches callback.

AS3 - NativeProcess that uses additional file

So I have an AIR app that runs an simple command-line program. The program basically takes in a file, decompresses it, and outputs the results. The only arguments I can give it are the input file, and it automatically outputs the results in the folder it's in. Naturally, I'm running the program using the NativeProcess class, which in turn needs a NativeProcessStartupInfo object to start.
Anyway, the NativeProcessStartupInfo's workingDirectory property is set to the folder of the file I'm going to put into the program, so that the decompressed results are put into that folder. However, the thing is that the program requires an additional file (a .dat) in the same directory as it to run. Which means that wherever workingDirectory is, that .dat needs to be there as well.
For the time being, I'm copying over the .dat and deleting it after the decompression is done. I was wondering though if there's a better way to do this? Is there a value in NativeProcess or NativeProcessStartupInfo that can help that I don't know about?

Matlab: Calling user defined function

I am creating a user defined function in this manner
function y=add(a)
y=a*a;
Now, this function is in a separate .m file.
I want to make use of this function but I am not getting it how to call it
Do I need another .m file to call it? and #include the above .m file?
First, you need to name the file add.m (i.e. exactly the same name your function has) and you can place it anywhere in the current matlab path (your current working directory is fine).
Second, you should call your function doing (e.g.) y=add(5) either from command line or from another matlab script/function.
In those scripts there's no need for further #include-like stuff, provided, again, add.m is in your working path.

In Octave, how do you source a file if the file name is stored in a variable?

I feel like this must be very easy, but I can't find the answer anywhere. In octave (and probably matlab but I haven't verified), you can source the contents of a file by doing
source /path/to/filename
However, let's say I have the filename stored in a variable called file. If you do source file, it treats file as the path rather than what is stored in file. I have tried inserting eval in various places but if that is the answer, I haven't found the correct invocation. I don't know much octave; there is surely a trivial answer to this that I am overlooking?
Not sure about octave, but try to use a function call
source(fname)
That's what you do in matlab at least.