]>
git.bts.cx Git - benzene.git/blob - src/bz/scripting/environment.c
1 #include <bz/scripting/environment_internal.h>
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>
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);
13 SVMVMConfiguration config = {
15 .free = free, // fixme
16 .lookup = bzScriptingBindingsLookupNativeFunction,
17 .lookupUserParam = lookupUserParam,
20 environment->vm = svmCreateVM(&config);
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) {
29 out->__raw = environment->publics[i].value.__raw;
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;
42 if (environment->publics[i].identifierHash == identifierHash) {
43 environment->publics[i].value.__raw = value.__raw;
47 bzError("Out of globals!!");