]> git.bts.cx Git - benzene.git/blob - src/bz/scripting/environment.c
Fixed Aseprite rendering system
[benzene.git] / src / bz / scripting / environment.c
1 #include <bz/scripting/environment_internal.h>
2
3 #include <bz/memory/allocator.h>
4 #include <bz/resources/resource.h>
5 #include <bz/scripting/bindings_internal.h>
6 #include <bz/scripting/script.h>
7
8 /*BZScriptingEnvironmentID bzScriptingMakeEnvironment(BZMemoryArenaID arena, void *lookupUserParam, const char *identifierFmt, ...) {
9 BZScriptingEnvironment *environment = bzMemoryAlloc(arena, sizeof(BZScriptingEnvironment));
10 environment->arena = arena;
11 bzInsertIdentifier(environment->identifier, identifierFmt);
12
13 SVMVMConfiguration config = {
14 .malloc = malloc,
15 .free = free, // fixme
16 .lookup = bzScriptingBindingsLookupNativeFunction,
17 .lookupUserParam = lookupUserParam,
18 };
19
20 environment->vm = svmCreateVM(&config);
21
22 return environment;
23 }
24
25 bool bzScriptingGetEnvironmentPublic(SVMOperand *out, BZScriptingEnvironmentID environment, BZIdentifierHash identifierHash) {
26 for (size_t i = 0; i < kBZScriptingEnvironmentPublicCount; ++i) {
27 if (environment->publics[i].identifierHash == identifierHash) {
28 if (out != NULL) {
29 out->__raw = environment->publics[i].value.__raw;
30 }
31 return true;
32 }
33 }
34 return false;
35 }
36
37 void bzScriptingSetEnvironmentPublic(BZScriptingEnvironmentID environment, BZIdentifierHash identifierHash, SVMOperand value) {
38 for (size_t i = 0; i < kBZScriptingEnvironmentPublicCount; ++i) {
39 if (environment->publics[i].identifierHash == 0) {
40 environment->publics[i].identifierHash = identifierHash;
41 }
42 if (environment->publics[i].identifierHash == identifierHash) {
43 environment->publics[i].value.__raw = value.__raw;
44 return;
45 }
46 }
47 bzError("Out of globals!!");
48 }*/