Advertisement Jump to content
Sign in to follow this  

Compiling a script into a stand-alone executable..

This topic is 4900 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, all, I have developed a scrpting language with quite a set of features. It seems to me that the next desirable feature is the ability to compile a script into a stand-alone executable, just like some other scripting languages do. I heard that the way to do it is to "rip" the interpreter from the language and combine it with the compiled script. This seems to me that I'll need to dive deeply into the binary format of the executable, which I am not quite good at. I am wondering if there is any other way to do this? Any response would be really appreciated. Thanks:)

Share this post

Link to post
Share on other sites
A comparatively simple method is to implement your interpreter as a collection of functions in a static link library, then embed the script as raw data and use a standard stub to feed the latter to the former. On Windows, for example, it is quite straightforward to add a text file to an executable as a binary resource using the Win32 API/SDK - that would be your script (or you can encrypt/compress it for obfuscation purposes, but I really wouldn't bother). I expect that such facilities will be equally readily available on all platforms.

Your application entry point (main, WinMain) then simply extracts the resource into a string buffer and passes it to the evaluation function from the interpreter. I'd say that this whole thing would talk all of about an afternoon to get running, then another day to tweak performance and deal with unforseen issues.

Happy hacking!

Share this post

Link to post
Share on other sites
Hi, Oluseyi,

I spent the whole afternoon working on this as you suggested, and made some progress. Now I have a converter to add a script as resource to the interpreter executable; and the interpreter can load the resource and convert it back to a script for executing. However, this works only for the Debug mode (I work with Visual C++ 6.0), when I tried to switch to the Release mode while keeping other things unchanged (as far as I can see), the interpreter executable seemed corrupted by the conversion, and Windows complained that the converted executable is not even a valid one. I then debugged the converter, going through it line by line, and found that each of the resource-related API functions returned ok. So it seemed to me that these APIs thought they have done their job correctly, which did not help much really.

I then found that under the Release mode, the original executable and the converted executable have exactly the same size, which does not make sense, since an additional script was added to the executable. Through a DOS "fc" (file comparing) command, I got the following message:
--------------- Begin of message ---------------
Comparing files...
000000D6: 04 03
000000D8: 79 6F
000000F1: 80 A0
00000121: 00 F0
00000122: 00 01
--------------- End of message ---------------
It seemed to me that the script is not properly added into the executable. However, as I said, I debugged the converter and it reported to me everything went ok.

Has anyone encountered the same problem before?

Thanks a lot.

Share this post

Link to post
Share on other sites
Now I've found out the solution. After I intentionally inserted a resource into the project and compiled it with the executable, and repeated the whole process again, and everything worked perfectly.

Another solution is to add a linking option "/incremental:yes". Everything worked ok when the change was made.

However weird these solutions are, they work, although gawkily; since the first method added unnecessary resource to the project and bloated the file size a bit, and the second bloated the file size by 1/3 because linking incrementally needs more space to handle relocations. To make a stupid guess, both of the two methods make room for the script resource by enlarging the file size? Any response is appreciated.

[Edited by - lgc_ustc on August 20, 2005 10:22:19 PM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!