|
kamac
|
 |
« Reply #15 on: February 17, 2012, 07:31:39 AM » |
|
WHAT LANGUAGE IS GOING TO BE INTERPRETED? If C++, you are probably out of luck (unless you are ok with a sort of modified C++ that drops some of the functionality). If another interpreted language you might be in luck. BASIC or either own made code (I think own-made code's better as it's going to be very simple functionality). Most interpreted languages package up the source with the player to create the exe. And this is what I'd want to know. How to do that. Say I've got code such as: ;action=move,5,0,1: ;end and some own-made .exe interpreter. How'd I append that code inside my .exe, so it wouldn't have to read it from some .txt file, but from it's own.
|
|
|
|
|
Logged
|
|
|
|
|
rivon
|
 |
« Reply #16 on: February 17, 2012, 07:36:47 AM » |
|
I already said one way - pack the scripts as strings in the C++ app and then just use some function which interprets the code from string. If C++, you are probably out of luck (unless you are ok with a sort of modified C++ that drops some of the functionality). If another interpreted language you might be in luck. Not so true. At least with C it's possible - TCC compiler can run C as a script (runtime interpreted). C++ might be a problem though.
|
|
|
|
|
Logged
|
|
|
|
|
kamac
|
 |
« Reply #17 on: February 17, 2012, 08:23:32 AM » |
|
I already said one way - pack the scripts as strings in the C++ app and then just use some function which interprets the code from string. How'd I append that code inside my .exe, so it wouldn't have to read it from some .txt file, but from it's own.
|
|
|
|
|
Logged
|
|
|
|
|
Netsu
|
 |
« Reply #18 on: February 17, 2012, 10:36:08 AM » |
|
Read this quotation carefully Kamac, Rivon already told you twice to save the scripts as strings in the C++ source code.
|
|
|
|
|
Logged
|
|
|
|
|
kamac
|
 |
« Reply #19 on: February 17, 2012, 10:45:41 AM » |
|
But this is quite strange. Say, i've got an IDE. Then, I write (in my edit field): print "something" As it would be code. Then, I press compile. And here it goes: How to write print "something" into an .exe, which is pre-made interpreter? I cannot save it to the source code, because there'd be no source code for that .exe (interpreter). Basically, I want to write some information into the .exe (which is the interpreter). If I didn't make this clear, then, uh.
|
|
|
|
|
Logged
|
|
|
|
|
Netsu
|
 |
« Reply #20 on: February 17, 2012, 10:52:34 AM » |
|
You won't be able to take a compiled executable interpreter taking input from the command line or whatever else and make it into something else. You can either: 1. Take an interpreter in the form of a library you can link to and use it in your code to interpret strings the way Rivon mentioned. or: 2. Create an application that would have the scripts you want to run compiled into it and would run them through a separate interpreter executable. Basically, you can't alter a compiled .exe, you need the sources. Or black magic. EDIT: Ok, there is another way, you can write a virtual machine capable of interpreting machine code that would run the compiled interpreter which itself would be compiled into the VM sources in binary form. But this is just silly 
|
|
|
|
|
Logged
|
|
|
|
|
kamac
|
 |
« Reply #21 on: February 17, 2012, 10:54:29 AM » |
|
That's what I actually wanted to know. Thanks.
@EDIT
Or actually one more thing.
Is there a possibility to have my interpreter source code & my user-typed code, then run compiler and make a .exe from that? (Compiler like mingw or gcc)
|
|
|
|
« Last Edit: February 17, 2012, 11:03:40 AM by kamac »
|
Logged
|
|
|
|
|
Netsu
|
 |
« Reply #22 on: February 17, 2012, 11:34:53 AM » |
|
Is there a possibility to have my interpreter source code & my user-typed code, then run compiler and make a .exe from that? (Compiler like mingw or gcc)
It wouldn't be as simple as running the compiler but it is possible and it is more or less what Rivon said. If you have the sources for a standalone interpreter then you would have to alter them so the interpreter would read input from string and not from the user, put your script in the string and compile. If you have sources for a library-style interpreter then the lib would probably already contain a function that reads a string and runs the interpreter on it, so all you need is put the script in a string and invoke the function is your app.
|
|
|
|
|
Logged
|
|
|
|
|
Flops
|
 |
« Reply #23 on: February 17, 2012, 12:43:27 PM » |
|
Let me try to explain it again:
1) You write your parser which reads a txt file and executes it accordingly. 2) You write a program which opens the exe using ios::binary and the txt file using ios:binary. 3) You concatenate both strings. 4) The resulting string is written to a file called 'new.exe'. 5) You launch 'new.exe'. 6) The behaviour is the same as 1) but the end of the exe is actually your text file. 7) You change your parser to open itself ('new.exe') instead of a text file. 8) The string which contains the data from the exe contains the executable data and the txt contents (which both is in 'new.exe' because you wrote it there earlier) gets stripped so it only contains the txt data. 9) Use the resulting string as you used the txt input before. 10) Party.
I tried this method and it works.
~Flops
|
|
|
|
|
Logged
|
|
|
|
|
mcc
|
 |
« Reply #24 on: February 17, 2012, 01:09:37 PM » |
|
 The string which contains the data from the exe contains the executable data and the txt contents (which both is in 'new.exe' because you wrote it there earlier) gets stripped so it only contains the txt How does this step work? Ie how can you tell where the "exe part" ends? EDIT; wait, missed your previous comment. hm
|
|
|
|
|
Logged
|
|
|
|
|
rivon
|
 |
« Reply #25 on: February 17, 2012, 01:26:40 PM » |
|
I would just do this: // main.cpp
#include "interpreter_library.h"
const char* script_code = " # script
print 'Hello, world!'
stuff() foo() ";
int main(int argc, char** argv) { interpret_script_from_string(script_code);
return 0; } I hope it's clear 
|
|
|
|
|
Logged
|
|
|
|
|
Flops
|
 |
« Reply #26 on: February 17, 2012, 01:41:38 PM » |
|
I would just do this: // main.cpp
#include "interpreter_library.h"
const char* script_code = " # script
print 'Hello, world!'
stuff() foo() ";
int main(int argc, char** argv) { interpret_script_from_string(script_code);
return 0; } I hope it's clear  The problem with this approach is that you have to recompile it every time you change the script. ~Flops
|
|
|
|
|
Logged
|
|
|
|
|
kamac
|
 |
« Reply #27 on: February 17, 2012, 02:48:46 PM » |
|
Thanks for all the input, it'll surely be a huge help! 
|
|
|
|
|
Logged
|
|
|
|
|
rivon
|
 |
« Reply #28 on: February 17, 2012, 05:42:58 PM » |
|
Flops: yeah, I know. I just wanted to show the basic idea.
|
|
|
|
|
Logged
|
|
|
|
|
14113
|
 |
« Reply #29 on: February 21, 2012, 11:52:17 AM » |
|
I write C++ software and often wonder if there is an easy-to-automate-in-a-makefile-or-something way to bundle resources inside of the .exe file on Windows. Right now I dump all my files into a folder named "Internal" which is sitting in the same folder with the exe. By using PhysFS I can bundle all of my resources into a single zip file, but that still requires two files (the exe, then the zip). It would be nice to just distribute one file and maybe a Readme (like is possible on the mac, where there is this "package" concept that allows you to place files inside of the .app).
not clean, or easy, but how about this:http://msdn.microsoft.com/en-us/library/7zxb70x7(v=vs.80).aspx
|
|
|
|
|
Logged
|
in fact, i prefer unpleasant forums
|
|
|
|