I'm using JSFL to writing some script, I need parse json string from some config files, so I need the JSFL can parse json string, but JSFL seems can't do this. then I thinks to include some json lib, like json.js, to JSFL file.
Way can I include the json.js file to my JSFL file?
Sorry for my english.
The absolute bare minimum would be:
// #include Config._jsfl
var scriptPath = FLfile.uriToPlatformPath(fl.scriptURI);
var scriptPathEnd = scriptPath.lastIndexOf("\\");
scriptPath = scriptPath.slice(0, scriptPathEnd + 1);
fl.runScript(FLfile.platformPathToURI(scriptPath + "Config._jsfl")); /*jsl:import Config._jsfl*/
This is more or less copied from my code, JSL tags included. I make the extensions on any libraries to be ._jsfl so that if it's in Flash's Commands folder, they don't show up in the menu.
I wrote a set of static classes (a Logging system, URI conversions, array utility functions) and wrote a global include function using them to automatically convert a relative path to an absolute URI based upon the running scripts location so that I could just say include("file._jsfl"); to simplify my scripts. HOWEVER all my scripts have to do that first include as shown above to gain the include function. Since my include function relies on a handful of static classes, I've not pasted it here.
Edit: spelling error.
If the library is local, you can store it in a subfolder of your Flash config path, i.e.
C:\Users\username\AppData\Local\Adobe\Flash CS6\language\Configuration\jslibs
Then, it is quite easy to include it in a single line:
fl.runScript(fl.configURI + "jslibs/file.js");
Related
I need to access a local JSON file. Since Grails 2.4 implements the AssetPipeline plugin by default, I saved my local JSON file at:
/grails-app/assets/javascript/vendor/me/json/local.json
Now what I need is to generate a URL to this JSON file, to be used as a function parameter on my JavaScript's $.getJSON() . I've tried using:
var URL.local = ""${ raw(asset.assetPath(src: "local.json")) }";
but it generates an invalid link:
console.log(URL.local);
// prints /project/assets/local.json
// instead of /project/assets/vendor/me/json/local.json
I also encountered the same scenario with images that are handled by AssetPipeline1.9.9— that are supposed to be inserted dynamically on the page. How can I generate the URL pointing this resource? I know, I can always provide a static String for the URL, but it seems there would be a more proper solution.
EDIT
I was asked if I could move the local JSON file directly under the assets/javascript root directory instead of placing it under a subdirectory to for an easier solution. I prefer not to, for organization purposes.
Have you tried asset.assetPath(src: "/me/json/local.json")
The assets plugin looks in all of the immediate children of assets/. Your local.json file would need to be placed in /project/assets/foo/ for your current code to pick it up.
Check out the relevant documentation here which contains an example.
The first level deep within the assets folder is simply used for organization purposes and can contain folders of any name you wish. File types also don't need to be in any specific folder. These folders are omitted from the URL mappings and relative path calculations.
I have a script which saves some files at a given location. It works fine but when I send this code to someone else, he has to change the paths in the code. It's not comfortable for someone who does not know what is in that code and for me to explain every time where and how the code should be changed.
I want to get this path in a variable which will be taken from the configuration file. So it will be easier for everyone to change just this config file and nothing in my code. But I have never done this before and could not find any information on how I can do this in the internet.
PS: I do not have any code and I ask about an ultimate solution but it is really difficult to find something good in the internet about dxl, especially since I'm new with that. Maybe someone of you already does that or has an idea how it could be done?
DXL has a perm to read the complete context of a file into a variable: string readFile (string) (or Buffer readFile (string))
you can split the output by \n and then use regular expressions to find all lines that match the pattern
^\s*([^;#].*)\s*=\s*(.*)\s*$
(i.e. key = value - where comment lines start with ; or #)
But in DOORS I prefer using DOORS modules as configuration modules. Object Heading can be the key, Object Text can be the value.
Hardcode the full name of the configuration module into your DXL file and the user can modify the behaviour of the application.
The advantage over a file is that you need not make assumptions on where the config file is to be stored on the file system.
It really depends on your situation. You are going to need to be a little more specific about what you mean by "they need to change the paths in the code". What are these paths to? Are they DOORS module paths, are they paths to local/network files, or are the something else entirely?
Like user3329561 said, you COULD use a DOORS module as a configuration file. I wouldn't recommend it though, simply because that is not what DOORS modules were designed for. DOORS is fully capable of reading system files in one line at a time as well as all at once, but I can't recommend that option either until I know what types of paths you want to load and why.
I suspect that there is a better solution for your problem that will present itself once more information is provided.
I had the same problem, I needed to specify the path of my configuration file used in my dxl script.
I solved this issue passing the directory path as a parameter to DOORS.exe as follow:
"...\DOORS\9.3\bin\doors.exe" -dxl "string myVar = \"Hello Word\"
then in my dxl script, the variable myVar is a global variable.
I am new to HLSL and in all of the tutorials I found there always seems to be a #include "Fxaa3_11.fxh" in each of them. I include this file and then it also makes a reference to another header file #include "Fxaa3_11.h" and as it goes I also include this file into my content pipeline and still gives me an error X1507: failed to open source file:... whichever way I go.
Is there any way to make a clean, single FXAA.fx file without enabling all this mess of external files?
If you want to compile your shader on the fly , you can use this function
Most important part when using includes is to provide a CompilerIncludeHandler ,include resolves are not automatically done for you (which is a good thing).
You override the open method, then read the include path from the parameters and return the content as a string.
If you just want to have if processed in content manager, Easiest way is probably just to copy paste the content of those header files in the main shader file (where the include is), and delete the include statement. Bit ugly but pretty simple.
Using luac5.1.exe is there anyway to pass it a string to create a binary file or does anyone know of any module that could create a syntax checked binary file, what I'm looking to do is create a settings file that can be loaded again by require.
Note that require loads lua source files or dynamic libraries. Yu might be better off with a custom loader if you really need binary data.
Two libraries that do this are Roberto's struct and lhf's lpack.
If you really want require then you could convert your binary data to strings, but since presumably that are userdata, you'll need a C function to translate the userdata to a Lua accessible type such as string or number.
Perhaps try this:
function compile(source,file)
io.open(file,"wb")
:write(string.dump(assert(loadstring(source,""))))
:close()
end
I would like to convert a bunch of fs files to fsx files.
Each of those fs file reference class defined in, say, base.fs
So instead of being compiled in the project and relying on the compiler resolution, all would be file based.
That means if I have all those file to include base.fsx, and that one file references another, base.fsx would be included twice.
Does anyone know how to make a conditional include with fsx files ?
The preprocessor documentation states
There is no #define preprocessor directive in F#. You must use the
compiler option or project settings to define the symbols used by the
#if directive.
If you're loading all the files from a single fsx script, then you can load the individual files from the project in the right order and the individual library files do not need to load base.fs directly - the code will be defined, because it has been loaded before.
For example, if you have base.fs:
module Base
let test() = 10
and you have more.fs which does not load base.fs but uses the functions defined there:
module More
let more () =
Base.test() + 1
then you can load all files in F# interactive (in, say, script.fsx) and it will work fine:
#load "base.fs"
#load "more.fs"
More.more()
The only disadvantage is that you won't get IntelliSense when editting more.fs (because the editor does not know about base.fs). To workaround that, it is probably a good idea to keep the files in a project in Visual Studio. But you can still load them in F# interactive for experimentation & testing.