Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created Amalgamation System #176

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ loss of use, data or profits, whether in an action of contract, negligence
or other tortious action, arising out of or in connection with the use or
performance of this software.



COMPILING

If you are building from source you can either use the provided Unix Makefile:
Expand All @@ -37,6 +39,34 @@ To install the MuJS command line interpreter, static library and header file:

make prefix=/usr/local install


SINGLE FILE

If you want to embed the interpreter using the single file version, just include "mujsAll.h" in your main and compile with:

gcc your_main.c -lm


~~~c
#include <stdio.h>
#include "mujsAll.h"

int main() {
js_State *J = js_newstate(NULL, NULL, JS_STRICT);

js_dostring(J, "var y = 10 + 20;");

js_getglobal(J, "y");
int result = js_tointeger(J, -1);
js_pop(J, 1);

printf("Result of exec: %d\n", result);

js_freestate(J);
return 0;
}
~~~

DOWNLOAD

The latest development source is available directly from the git repository:
Expand Down
57 changes: 57 additions & 0 deletions amalgamate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from os.path import join

def get_action(referencer_dir: str, line: str) -> str or None:
line = line.strip()
if not line.startswith('#include'):
return None

if '"' in line:
relative_file = line.split('"')[1]
return join(referencer_dir, relative_file)



def generate_amalgamated_code(starter: str) -> str:
"""generate an full amalgamated code of the code you pass
Args:
starter (str): the started path of your code ex:'test.h'
output (str): the output you want to save, if its None it will not save nothing
Raises:
FileNotFoundError: if some file were not found

Returns:
str: The full amalgamated code
"""
current_text = ''
try:
with open(starter) as f:
# get current dir name
current_dir = '/'.join(starter.split('/')[:-1])
lines = f.readlines()
for line in lines:
##trim line
file_to_include = get_action(current_dir, line)
if file_to_include == None:
current_text += line
continue

else:
current_text += generate_amalgamated_code(file_to_include)

except FileNotFoundError:
raise FileNotFoundError(f'FileNotFoundError: {starter}')


return '\n' + current_text +'\n'


def main():

definitions = generate_amalgamated_code('mujs/one.c')
with open('mujs/mujs.h','r') as arq:
declarations = arq.read()
final = declarations.replace('//definition_point',definitions) +'\n'
with open('mujsAll.h','w') as arq2:
arq2.write(final)

main()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions mujs.h → mujs/mujs.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ int js_type(js_State *J, int idx);
void js_repr(js_State *J, int idx);
const char *js_torepr(js_State *J, int idx);
const char *js_tryrepr(js_State *J, int idx, const char *error);
//dont delete the next comment
//definition_point

#ifdef __cplusplus
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading