-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-added (and updated) Lua as a built-in choice for scripting. Yay!
- Loading branch information
Showing
7 changed files
with
5,093 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[submodule "system/script/lua/lua"] | ||
path = system/script/lua/lua | ||
url = https://github.com/lua/lua | ||
[submodule "system/script/lua/src/lua"] | ||
path = system/script/lua/src/lua | ||
url = https://github.com/lua/lua |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,269 @@ | ||
#include <topaz/matrix.h> | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
static void topaz_script_return_matrix( | ||
topazScript_t * script, | ||
topazScript_Object_t * fn, | ||
topazMatrix_t * a | ||
) { | ||
|
||
topazScript_Object_t * args[] = { | ||
topaz_script_object_from_number(script, a->data[0]), | ||
topaz_script_object_from_number(script, a->data[1]), | ||
topaz_script_object_from_number(script, a->data[2]), | ||
topaz_script_object_from_number(script, a->data[3]), | ||
|
||
topaz_script_object_from_number(script, a->data[4]), | ||
topaz_script_object_from_number(script, a->data[5]), | ||
topaz_script_object_from_number(script, a->data[6]), | ||
topaz_script_object_from_number(script, a->data[7]), | ||
|
||
topaz_script_object_from_number(script, a->data[8]), | ||
topaz_script_object_from_number(script, a->data[9]), | ||
topaz_script_object_from_number(script, a->data[10]), | ||
topaz_script_object_from_number(script, a->data[11]), | ||
|
||
topaz_script_object_from_number(script, a->data[12]), | ||
topaz_script_object_from_number(script, a->data[13]), | ||
topaz_script_object_from_number(script, a->data[14]), | ||
topaz_script_object_from_number(script, a->data[15]) | ||
|
||
}; | ||
|
||
topaz_script_object_destroy( | ||
topaz_script_object_reference_call( | ||
fn, | ||
TOPAZ_ARRAY_CAST(args, topazScript_Object_t *, 16) | ||
) | ||
); | ||
topaz_script_object_destroy(args[0]); | ||
topaz_script_object_destroy(args[1]); | ||
topaz_script_object_destroy(args[2]); | ||
topaz_script_object_destroy(args[3]); | ||
|
||
topaz_script_object_destroy(args[4]); | ||
topaz_script_object_destroy(args[5]); | ||
topaz_script_object_destroy(args[6]); | ||
topaz_script_object_destroy(args[7]); | ||
|
||
topaz_script_object_destroy(args[8]); | ||
topaz_script_object_destroy(args[9]); | ||
topaz_script_object_destroy(args[10]); | ||
topaz_script_object_destroy(args[11]); | ||
|
||
topaz_script_object_destroy(args[12]); | ||
topaz_script_object_destroy(args[13]); | ||
topaz_script_object_destroy(args[14]); | ||
topaz_script_object_destroy(args[15]); | ||
|
||
} | ||
|
||
topazMatrix_t topaz_script_object_to_matrix(topazScript_t * script, topazScript_Object_t * arg) { | ||
topazMatrix_t a = {}; | ||
int i; | ||
for(i = 0; i < 16; ++i) { | ||
a.data[i] = topaz_script_object_as_number( | ||
topaz_script_object_reference_array_get_nth(arg, i) | ||
); | ||
} | ||
return a; | ||
} | ||
|
||
|
||
TSO_SCRIPT_API_FN(matrix_api__set_identity) { | ||
TSO_ARG_0; | ||
TSO_ARG_1; | ||
|
||
topazMatrix_t a; | ||
topaz_matrix_set_identity(&a); | ||
topaz_script_return_matrix(script, arg1, &a); | ||
TSO_NO_RETURN; | ||
} | ||
|
||
TSO_SCRIPT_API_FN(matrix_api__transform) { | ||
TSO_ARG_0; | ||
|
||
TSO_ARG_1; | ||
TSO_ARG_2; | ||
TSO_ARG_3; | ||
|
||
TSO_ARG_4; | ||
|
||
topazMatrix_t a = topaz_script_object_to_matrix(script, arg0); | ||
topazVector_t b = { | ||
topaz_script_object_as_number(arg1), | ||
topaz_script_object_as_number(arg2), | ||
topaz_script_object_as_number(arg3) | ||
}; | ||
|
||
topazVector_t c = topaz_matrix_transform(&a, &b); | ||
|
||
topaz_matrix_set_identity(&a); | ||
topaz_script_return_vector(script, arg1, c.x, c.y, c.z); | ||
TSO_NO_RETURN; | ||
} | ||
|
||
TSO_SCRIPT_API_FN(matrix_api__to_string) { | ||
TSO_ARG_0; | ||
|
||
topazMatrix_t a = topaz_script_object_to_matrix(script, arg0); | ||
topazString_t * str = topaz_matrix_to_string(&a); | ||
topazScript_Object_t * o = topaz_script_object_from_string(script, str); | ||
topaz_string_destroy(str); | ||
return o; | ||
} | ||
|
||
TSO_SCRIPT_API_FN(matrix_api__transpose) { | ||
TSO_ARG_0; | ||
TSO_ARG_1; | ||
|
||
topazMatrix_t a = topaz_script_object_to_matrix(script, arg0); | ||
topaz_matrix_transpose(&a); | ||
topaz_script_return_matrix(script, arg1, &a); | ||
TSO_NO_RETURN; | ||
} | ||
|
||
|
||
TSO_SCRIPT_API_FN(matrix_api__invert) { | ||
TSO_ARG_0; | ||
TSO_ARG_1; | ||
|
||
topazMatrix_t a = topaz_script_object_to_matrix(script, arg0); | ||
topaz_matrix_invert(&a); | ||
topaz_script_return_matrix(script, arg1, &a); | ||
TSO_NO_RETURN; | ||
} | ||
|
||
TSO_SCRIPT_API_FN(matrix_api__reverse_majority) { | ||
TSO_ARG_0; | ||
TSO_ARG_1; | ||
|
||
topazMatrix_t a = topaz_script_object_to_matrix(script, arg0); | ||
topaz_matrix_reverse_majority(&a); | ||
topaz_script_return_matrix(script, arg1, &a); | ||
TSO_NO_RETURN; | ||
} | ||
|
||
TSO_SCRIPT_API_FN(matrix_api__multiply) { | ||
TSO_ARG_0; | ||
TSO_ARG_1; | ||
TSO_ARG_2; | ||
TSO_ARG_3; | ||
|
||
topazMatrix_t a = topaz_script_object_to_matrix(script, arg0); | ||
topazMatrix_t b = topaz_script_object_to_matrix(script, arg1); | ||
topazMatrix_t c = topaz_matrix_multiply(&a, &b); | ||
topaz_script_return_matrix(script, arg3, &c); | ||
TSO_NO_RETURN; | ||
} | ||
|
||
TSO_SCRIPT_API_FN(matrix_api__rotate_by_angles) { | ||
TSO_ARG_0; | ||
|
||
TSO_ARG_1; | ||
TSO_ARG_2; | ||
TSO_ARG_3; | ||
|
||
TSO_ARG_4; | ||
|
||
topazMatrix_t a = topaz_script_object_to_matrix(script, arg0); | ||
topaz_matrix_rotate_by_angles( | ||
&a, | ||
topaz_script_object_as_number(arg1), | ||
topaz_script_object_as_number(arg2), | ||
topaz_script_object_as_number(arg3) | ||
); | ||
topaz_script_return_matrix(script, arg4, &a); | ||
TSO_NO_RETURN; | ||
} | ||
|
||
TSO_SCRIPT_API_FN(matrix_api__rotate_by_axis) { | ||
TSO_ARG_0; | ||
|
||
TSO_ARG_1; | ||
TSO_ARG_2; | ||
TSO_ARG_3; | ||
TSO_ARG_4; | ||
|
||
TSO_ARG_5; | ||
|
||
topazMatrix_t a = topaz_script_object_to_matrix(script, arg0); | ||
topaz_matrix_rotate_by_axis( | ||
&a, | ||
topaz_script_object_as_number(arg1), | ||
topaz_script_object_as_number(arg2), | ||
topaz_script_object_as_number(arg3), | ||
topaz_script_object_as_number(arg4) | ||
); | ||
topaz_script_return_matrix(script, arg5, &a); | ||
TSO_NO_RETURN; | ||
} | ||
|
||
|
||
TSO_SCRIPT_API_FN(matrix_api__translate) { | ||
TSO_ARG_0; | ||
|
||
TSO_ARG_1; | ||
TSO_ARG_2; | ||
TSO_ARG_3; | ||
|
||
TSO_ARG_4; | ||
|
||
topazMatrix_t a = topaz_script_object_to_matrix(script, arg0); | ||
topaz_matrix_translate( | ||
&a, | ||
topaz_script_object_as_number(arg1), | ||
topaz_script_object_as_number(arg2), | ||
topaz_script_object_as_number(arg3) | ||
); | ||
topaz_script_return_matrix(script, arg4, &a); | ||
TSO_NO_RETURN; | ||
} | ||
|
||
TSO_SCRIPT_API_FN(matrix_api__scale) { | ||
TSO_ARG_0; | ||
|
||
TSO_ARG_1; | ||
TSO_ARG_2; | ||
TSO_ARG_3; | ||
|
||
TSO_ARG_4; | ||
|
||
topazMatrix_t a = topaz_script_object_to_matrix(script, arg0); | ||
topaz_matrix_scale( | ||
&a, | ||
topaz_script_object_as_number(arg1), | ||
topaz_script_object_as_number(arg2), | ||
topaz_script_object_as_number(arg3) | ||
); | ||
topaz_script_return_matrix(script, arg4, &a); | ||
TSO_NO_RETURN; | ||
} | ||
|
||
static void add_refs__matrix_api(topazScript_t * script, topazScriptManager_t * context) { | ||
|
||
// member functions | ||
TS_MAP_NATIVE_FN("topaz_matrix__set_identity", matrix_api__set_identity, 2); | ||
TS_MAP_NATIVE_FN("topaz_matrix__transform", matrix_api__transform, 5); | ||
TS_MAP_NATIVE_FN("topaz_matrix__to_string", matrix_api__to_string, 1); | ||
TS_MAP_NATIVE_FN("topaz_matrix__transpose", matrix_api__transpose, 2); | ||
TS_MAP_NATIVE_FN("topaz_matrix__invert", matrix_api__invert, 2); | ||
TS_MAP_NATIVE_FN("topaz_matrix__reverse_majority", matrix_api__reverse_majority, 2); | ||
TS_MAP_NATIVE_FN("topaz_matrix__multiply", matrix_api__multiply, 4); | ||
TS_MAP_NATIVE_FN("topaz_matrix__rotate_by_angles", matrix_api__rotate_by_angles, 5); | ||
TS_MAP_NATIVE_FN("topaz_matrix__rotate_by_angles", matrix_api__rotate_by_axis, 6); | ||
TS_MAP_NATIVE_FN("topaz_matrix__translate", matrix_api__translate, 5); | ||
TS_MAP_NATIVE_FN("topaz_matrix__scale", matrix_api__scale, 5); | ||
|
||
|
||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
Copyright (c) 2020, Johnathan Corkery. (jcorkery@umich.edu) | ||
All rights reserved. | ||
This file is part of the topaz project (https://github.com/jcorks/topaz) | ||
topaz was released under the MIT License, as detailed below. | ||
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. | ||
*/ | ||
|
||
#include <topaz/backends/script.h> | ||
#include <topaz/system.h> | ||
|
||
#ifndef H_TOPAZDC__SCRIPT_LUA__INCLUDED | ||
#define H_TOPAZDC__SCRIPT_LUA__INCLUDED | ||
|
||
void topaz_system_script_lua__backend( | ||
topazSystem_t * system, | ||
topazSystem_Backend_t * backend, | ||
topazScriptAPI_t * api | ||
); | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <stdio.h> | ||
#include <stdint.h> | ||
|
||
int main() { | ||
char * files_in[] = { | ||
"topaz.lua" | ||
}; | ||
|
||
char * files_out[] = { | ||
"bootstrap_bytes" | ||
}; | ||
|
||
char * files_ref[] = { | ||
"const uint8_t bootstrap_bytes[]={" | ||
}; | ||
|
||
uint32_t n; | ||
for(n = 0; n < 1; ++n) { | ||
|
||
|
||
FILE * in = fopen(files_in[n], "rb"); | ||
FILE * out = fopen(files_out[n], "wb"); | ||
|
||
fprintf(out, files_ref[n]); | ||
#define CHUNK_SIZE (1024*4) | ||
uint32_t readSize; | ||
uint32_t i; | ||
char dataRead[CHUNK_SIZE]; | ||
|
||
while((readSize = fread(dataRead, 1, CHUNK_SIZE, in))) { | ||
for(i = 0; i < readSize; ++i) { | ||
fprintf(out, "0x%02x,", dataRead[i]); | ||
if (i%32==0) | ||
fprintf(out, "\n"); | ||
} | ||
} | ||
fprintf(out, "0x00};"); | ||
|
||
fclose(in); | ||
fclose(out); | ||
} | ||
} |
Oops, something went wrong.