mirror of https://github.com/mode777/rayjs.git
				
				
				
			Compare commits
	
		
			7 Commits
		
	
	
		
			pre-4.6-de
			...
			main
		
	
	| Author | SHA1 | Date | 
|---|---|---|
|  | 2ef1a00038 | |
|  | a3ed6bdb2f | |
|  | d967c49c45 | |
|  | 77cebb3dce | |
|  | 0c3a54b309 | |
|  | 1579be5d1d | |
|  | 52695d8a99 | 
|  | @ -1,5 +1,12 @@ | ||||||
| cmake_minimum_required(VERSION 3.1) | cmake_minimum_required(VERSION 3.1) | ||||||
| set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "" FORCE) | set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "" FORCE) | ||||||
|  | 
 | ||||||
|  | # Workaround for windows to prevent static linking of pthread | ||||||
|  | IF (WIN32) | ||||||
|  | 	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static") | ||||||
|  | 	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static") | ||||||
|  | ENDIF() | ||||||
|  | 
 | ||||||
| project(rayjs) | project(rayjs) | ||||||
| 
 | 
 | ||||||
| message("=== Configure raylib ===") | message("=== Configure raylib ===") | ||||||
|  |  | ||||||
|  | @ -0,0 +1,21 @@ | ||||||
|  | MIT License | ||||||
|  | 
 | ||||||
|  | Copyright (c) 2023 Alexander Klingenbeck | ||||||
|  | 
 | ||||||
|  | Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
|  | of this software and associated documentation files (the "Software"), to deal | ||||||
|  | in the Software without restriction, including without limitation the rights | ||||||
|  | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||||
|  | copies of the Software, and to permit persons to whom the Software is | ||||||
|  | furnished to do so, subject to the following conditions: | ||||||
|  | 
 | ||||||
|  | The above copyright notice and this permission notice shall be included in all | ||||||
|  | copies or substantial portions of the Software. | ||||||
|  | 
 | ||||||
|  | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||||
|  | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||||
|  | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||||
|  | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||||
|  | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||||
|  | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||||
|  | SOFTWARE. | ||||||
|  | @ -14,7 +14,7 @@ rayjs is not a binding for NodeJS nor is it running in the browser (yet). It's c | ||||||
| * In-depth auto-complete with definitions for the whole API | * In-depth auto-complete with definitions for the whole API | ||||||
| 
 | 
 | ||||||
| ## Getting started | ## Getting started | ||||||
| 1. Download the binary for your platform from the release section. | 1. Download the binary for your platform from the [release section](https://github.com/mode777/rayjs/releases). | ||||||
| 2. Unzip the executable to a folder and create a new text file in the same folder. Rename the file to `main.js` | 2. Unzip the executable to a folder and create a new text file in the same folder. Rename the file to `main.js` | ||||||
| 3. Open the file with a text-editor (e.g. Notepad) and add the following code | 3. Open the file with a text-editor (e.g. Notepad) and add the following code | ||||||
|     ```javascript |     ```javascript | ||||||
|  | @ -103,6 +103,7 @@ rayjs comes with full auto-complete support in the form of the definitions file | ||||||
|   } |   } | ||||||
| } | } | ||||||
| ``` | ``` | ||||||
|  | After that put the `lib.raylib.d.ts` file in the same folder and optionally restart your IDE. Auto-complete should be working: | ||||||
|  |  | ||||||
| 
 | 
 | ||||||
| ## Examples | ## Examples | ||||||
|  |  | ||||||
|  | @ -241,6 +241,81 @@ JSModuleDef *js_module_loader(JSContext *ctx, | ||||||
|     return m; |     return m; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | /* load and evaluate a file */ | ||||||
|  | static JSValue js_loadScript(JSContext *ctx, JSValueConst this_val, | ||||||
|  |                              int argc, JSValueConst *argv) | ||||||
|  | { | ||||||
|  |     uint8_t *buf; | ||||||
|  |     const char *filename; | ||||||
|  |     JSValue ret; | ||||||
|  |     size_t buf_len; | ||||||
|  |      | ||||||
|  |     filename = JS_ToCString(ctx, argv[0]); | ||||||
|  |     if (!filename) | ||||||
|  |         return JS_EXCEPTION; | ||||||
|  |     buf = js_load_file(ctx, &buf_len, filename); | ||||||
|  |     if (!buf) { | ||||||
|  |         JS_ThrowReferenceError(ctx, "could not load '%s'", filename); | ||||||
|  |         JS_FreeCString(ctx, filename); | ||||||
|  |         return JS_EXCEPTION; | ||||||
|  |     } | ||||||
|  |     ret = JS_Eval(ctx, (char *)buf, buf_len, filename, | ||||||
|  |                   JS_EVAL_TYPE_GLOBAL); | ||||||
|  |     js_free(ctx, buf); | ||||||
|  |     JS_FreeCString(ctx, filename); | ||||||
|  |     return ret; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static JSValue js_print(JSContext *ctx, JSValueConst this_val, | ||||||
|  |                               int argc, JSValueConst *argv) | ||||||
|  | { | ||||||
|  |     int i; | ||||||
|  |     const char *str; | ||||||
|  |     size_t len; | ||||||
|  | 
 | ||||||
|  |     for(i = 0; i < argc; i++) { | ||||||
|  |         if (i != 0) | ||||||
|  |             putchar(' '); | ||||||
|  |         str = JS_ToCStringLen(ctx, &len, argv[i]); | ||||||
|  |         if (!str) | ||||||
|  |             return JS_EXCEPTION; | ||||||
|  |         fwrite(str, 1, len, stdout); | ||||||
|  |         JS_FreeCString(ctx, str); | ||||||
|  |     } | ||||||
|  |     putchar('\n'); | ||||||
|  |     return JS_UNDEFINED; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void js_std_add_helpers(JSContext *ctx, int argc, char **argv) | ||||||
|  | { | ||||||
|  |     JSValue global_obj, console, args; | ||||||
|  |     int i; | ||||||
|  | 
 | ||||||
|  |     /* XXX: should these global definitions be enumerable? */ | ||||||
|  |     global_obj = JS_GetGlobalObject(ctx); | ||||||
|  | 
 | ||||||
|  |     console = JS_NewObject(ctx); | ||||||
|  |     JS_SetPropertyStr(ctx, console, "log", | ||||||
|  |                       JS_NewCFunction(ctx, js_print, "log", 1)); | ||||||
|  |     JS_SetPropertyStr(ctx, global_obj, "console", console); | ||||||
|  | 
 | ||||||
|  |     /* same methods as the mozilla JS shell */ | ||||||
|  |     if (argc >= 0) { | ||||||
|  |         args = JS_NewArray(ctx); | ||||||
|  |         for(i = 0; i < argc; i++) { | ||||||
|  |             JS_SetPropertyUint32(ctx, args, i, JS_NewString(ctx, argv[i])); | ||||||
|  |         } | ||||||
|  |         JS_SetPropertyStr(ctx, global_obj, "scriptArgs", args); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     JS_SetPropertyStr(ctx, global_obj, "print", | ||||||
|  |                       JS_NewCFunction(ctx, js_print, "print", 1)); | ||||||
|  |     JS_SetPropertyStr(ctx, global_obj, "__loadScript", | ||||||
|  |                       JS_NewCFunction(ctx, js_loadScript, "__loadScript", 1)); | ||||||
|  |      | ||||||
|  |     JS_FreeValue(ctx, global_obj); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| static int js_run(int argc, char** argv){ | static int js_run(int argc, char** argv){ | ||||||
|     TraceLog(LOG_INFO, "Starting QuickJS"); |     TraceLog(LOG_INFO, "Starting QuickJS"); | ||||||
|     rt = JS_NewRuntime(); |     rt = JS_NewRuntime(); | ||||||
|  | @ -259,7 +334,7 @@ static int js_run(int argc, char** argv){ | ||||||
| 
 | 
 | ||||||
|     JS_SetModuleLoaderFunc(rt, NULL, js_module_loader, NULL); |     JS_SetModuleLoaderFunc(rt, NULL, js_module_loader, NULL); | ||||||
|      |      | ||||||
|     //js_std_add_helpers(ctx, argc, argv);
 |     js_std_add_helpers(ctx, argc, argv); | ||||||
| 
 | 
 | ||||||
|     const char *str = "import * as rl from 'raylib'\n"  |     const char *str = "import * as rl from 'raylib'\n"  | ||||||
|                       "for (const key in rl) { globalThis[key] = rl[key] }\n"; |                       "for (const key in rl) { globalThis[key] = rl[key] }\n"; | ||||||
|  |  | ||||||
|  | @ -1 +1 @@ | ||||||
| Subproject commit 44659b7ba8bd6d517d75fac8675ecd026f713240 | Subproject commit d3ea64983212f7451a9cfbf644da8a5c43dbc706 | ||||||
		Loading…
	
		Reference in New Issue