AngelScript, how to load a script file? - c++

I know how I can bind C++ functions to AngelScript, but in my C++ code, how do I load an .as script file? How can I say in my C++ "Execute myscript.as now!" ?
In the AngelScript API I don't find any function like "LoadScript" or "ExecuteScript".
Or do I have to define a path somewhere from where AngelScript loads all scripts and I don't need to tell it the exact files?

Just found it out (in a small side sentence in the docs):
AngelScript doesn't provide a build in file loading. That's why there is no API function. So the manual loading is indeed the only way.

asIScriptModule::AddScriptSection will load a script string. asIScriptContext::Execute will execute a function from a script. The documentation was pretty clear about all of this; you might want to give it a look.

Related

c++ what is the *clever* way of creating setup program and handle extraction

I know how to create and code my own setup program but i need to be redirected at some point. This point i'm sure inlight other people too.
I created a setup project. All is done. Except, installation files inside of EXE.
I know 2 different ways of doing this:
Create resource in EXE and embed RAR/ZIP file.
Put compressed archive with files along with EXE. EXE will read contents and data from this protected and compressed ZIP.
But what i want is number 1. I want to embed it. But;
What is the proper way of embedding this? Are other setup creators do the same thing? Embed resource as compressed single zip in EXE? Or do they another trick?
How do you extract files? On the fly by memory? Like read each file one-by-one. Synced. Or first, copy ZIP to temp and extract from it.
Or even embed all files separately to the resources.
I, even think that if i should create simple MSI without dialogs and embed it and run from background but i want to take all control. I want everything belongs to the original setup that i created.
Note:
I want to make my own dialogs, effects, procedures, functions and
steps. Yes, MSI is acceptable but i will stick with its features. Oh,
If im able to extend it, why should i spent more time doing this
instead of making my own? I am so confused... I am talking about very big setup project here. Not just a standard ugly UI with less features. At least, im gonna try :)
Do not give me any sample/code just show me a correct path, please.
Best options here:
Create ZIP compatible EXE that reads itself as ZIP and read the file list and extract.
Create non-zip compatible EXE that has a hidden body somewhere and read that area (seek) and get the list & extract.
The proper way to do it is to use the Windows installer technology, aka MSI. There is a nice, Microsoft blessed toolset called WiX that you can use to greatly simplify the process.
http://wix.codeplex.com/
If you are truly intent on reinventing the wheel, you can look through the source code to WiX on how things are done.
Best options here:
Create ZIP compatible EXE that reads itself as ZIP and read the file list and extract.
Create non-zip compatible EXE that has a hidden body somewhere and read that area (seek) and get the list & extract.
Why write your own? Much easier to use WiX (http://wixtoolset.org/) with optionally a graphical interface like WiXEdit (http://wixedit.sourceforge.net/). Have you thought about additional requirements like uninstall etc...
Good luck!
Would InnoSetup help with your problem? You can personalise the dialogs and extend its functionality quite a lot.

python-sip: How to access a DLL from both Python and C++

I have a C++ GUI, it load a DLL when running. I use SIP to import the DLL in python. I need to embed the python part in the GUI, and some data are needed to exchange between python and C++.
For example, in the C++ GUI, I can enter command from a panel, such as "drawSomething()", it will call corresponding function in python, and the result will be shown in the GUI.
Can I use SIP to
extract a C++ object from python object (just like the way boost.python does), or is there a better way to share data between python and c++ seamlessly?
thanks.
It turns out that I do not need to do anything complicated...
In my case, there is no difference to call functions in DLL from C++ or from python code embedded in C++.
I am totally over-thinked.
Please take a look at this Library
http://www.swig.org/Doc1.3/Python.html

Use Node.js as an interpreter

I would like to embed NodeJS in my application. The reason i would like to use NodeJS and not just the V8 directly, is because of the extensions that exist for NodeJS.
To do that i understand that i need to compile NodeJS with GYP. Got it. But how do i work with it? is there a static lib to link to? how to start it up? say i want to provide it with a V8 context, how do i pass it?
a bit at a loss here. hope for help.
Note - i want to activate nodejs from my C++ code, not the other way around. i understand extensions, this is not what i want.
Regards,
Gal.
As I got from this question the problem of immediate linking with node.js is still unsolved. Actually the workaround may be running it in a separated process like an ordinary command line application. You may save your script to file, pass it as cmdline argument, then obtain std output from the node.js executable.

How to use V8's built in functions

I'm new in both javascript and V8. According to Google's Embedder's Guide, I saw something in the context section talking about built-in utility javascript functions. And I also found some .js files(e.g. math.js) in the downloaded source code, so I tried to write a simple program to call functions in these files, but I failed.
Does a context created by Persistent<Context> context = Context::New() have any built-in js functions? How can I access them?
Is there a way to first import existing js files as a library(something like src="xxx" type="text/javascript" in HTML page) and then run my own execute script?
Can I call google maps api through the embedded V8 library in app? How?
3. Google Maps needs a full browser DOM (or at least XMLHttpRequest I guess), you can't use it from just a Javascript library.
I think v8 gives you the Math.* functions for free.
You need to implement everything else yourself though, like loading other javascript files. shell.cc has some of the functions you might be looking for.
As for the maps API, I believe you would need a full blown rendering engine/javascript engine combo for that. You might be better off taking a look at Webkit or something that you can use to embed Webkit for what you're looking to do, I can't really say.
You can use for example the --allow_natives_syntax or --expose_natives_as option.
Here are examples with MathLog picked at random in src/math.js:
First compile a shell with
$ scons d8 -j8
Then use --expose_natives_as:
$ ./d8 --expose_natives_as nat
V8 version 3.12.7 (candidate) [console: dumb]
d8> nat.MathLog(100)
4.605170185988092
or use --allow_natives_syntax with the '%' prefix:
$ ./d8 --allow_natives_syntax
V8 version 3.12.7 (candidate) [console: dumb]
d8> %MathLog(100)
4.605170185988092

Differing paths for lua script and app

My problem is that I'm having trouble specifying paths for Lua to look in.
For example, in my script I have a require("someScript") line that works perfectly (it is able to use functions from someScript when the script is run standalone.
However, when I run my app, the script fails. I believe this is because Lua is looking in a location relative to the application rather than relative to the script.
Hardcoding the entire path down to the drive isn't an option since people can download the game wherever they like so the highest I can go is the root folder for the game.
We have XML files to load in information on objects. In them, when we specify the script the object uses, we only have to do something like Content/Core/Scripts/someScript.lua where Content is in the same directory as Debug and the app is located inside Debug. If I try putting that (the Content/Core...) in Lua's package.path I get errors when I try to run the script standalone.
I'm really stuck, and am not sure how to solve this. Any help is appreciated. Thanks.
P.S. When I print out the default package.path in the app I see syntax like ;.\?.lua
in a sequence like...
;.\?.lua;c:...(long file path)\Debug\?.lua; I assume the ; means the end of the path, but I have no idea what the .\?.lua means. Any Lua file in the directory?
You can customize the way require loads modules by putting your own loader into the package.loaders table. See here:
http://www.lua.org/manual/5.1/manual.html#pdf-package.loaders
If you want to be sure that things are nicely sandboxed, you'll probably want to remove all the default loaders and replace them with one that does exactly what you want and nothing more. (It will probably be somewhat similar to one of the existing ones, so you can use those as a guide.)