Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 503345d

Browse files
committed
[[ Module Lcext ]] Allow module section to be a module name to resolve
This patch changes the deploy capsule for module files to permit either the data of a module file or the name of a module to lookup. If it is a name then the module should be included in the standalone as a builtin.
1 parent 21a2275 commit 503345d

File tree

3 files changed

+65
-38
lines changed

3 files changed

+65
-38
lines changed

engine/src/mode_standalone.cpp

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -389,28 +389,56 @@ bool MCStandaloneCapsuleCallback(void *p_self, const uint8_t *p_digest, MCCapsul
389389
return false;
390390
}
391391

392-
MCAutoValueRefBase<MCStreamRef> t_stream;
393-
if (!MCMemoryInputStreamCreate(t_module_data.Bytes(),
394-
p_length, &t_stream))
392+
// This section is raw file data either a module or a name to resolve which should
393+
// have been added as a builtin
394+
bool t_is_module = true;
395+
if (p_length >= 4 &&
396+
!(t_module_data.Bytes()[0] == 'L' &&
397+
t_module_data.Bytes()[1] == 'C' &&
398+
t_module_data.Bytes()[2] == ((kMCScriptCurrentModuleVersion >> 0) & 0xFF) &&
399+
t_module_data.Bytes()[3] == ((kMCScriptCurrentModuleVersion >> 8) & 0xFF)))
395400
{
396-
MCresult -> sets("out of memory");
397-
return false;
401+
t_is_module = false;
398402
}
399403

400404
MCAutoScriptModuleRefArray t_modules;
401-
if (!MCScriptCreateModulesFromStream(*t_stream, t_modules))
405+
MCScriptModuleRef t_main;
406+
407+
if (t_is_module)
402408
{
403-
MCAutoErrorRef t_error;
404-
if (MCErrorCatch(&t_error))
405-
MCresult->setvalueref(MCErrorGetMessage(*t_error));
406-
else
407-
MCresult->sets("out of memory");
409+
MCAutoValueRefBase<MCStreamRef> t_stream;
410+
if (!MCMemoryInputStreamCreate(t_module_data.Bytes(),
411+
p_length, &t_stream))
412+
{
413+
MCresult -> sets("out of memory");
414+
return false;
415+
}
408416

409-
return false;
417+
if (!MCScriptCreateModulesFromStream(*t_stream, t_modules))
418+
{
419+
MCAutoErrorRef t_error;
420+
if (MCErrorCatch(&t_error))
421+
MCresult->setvalueref(MCErrorGetMessage(*t_error));
422+
else
423+
MCresult->sets("out of memory");
424+
425+
return false;
426+
}
427+
428+
t_main = t_modules[0];
429+
}
430+
else
431+
{
432+
MCNewAutoNameRef t_name;
433+
if (!MCNameCreateWithNativeChars(t_module_data.Bytes(), p_length, &t_name) ||
434+
!MCScriptLookupModule(*t_name, t_main) ||
435+
!t_modules.Push(t_main))
436+
{
437+
MCresult->sets("out of memory");
438+
return false;
439+
}
410440
}
411441

412-
MCScriptModuleRef t_main = t_modules[0];
413-
414442
MCAutoStringRef t_module_resources;
415443
if (!MCStringFormat(&t_module_resources, "%@/resources",
416444
MCScriptGetNameOfModule(t_main)))

libscript/include/libscript/script.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,29 @@ typedef struct MCScriptForeignHandlerInfo *MCScriptForeignHandlerInfoRef;
582582
bool MCScriptForeignHandlerInfoParse(MCStringRef p_binding, MCScriptForeignHandlerInfoRef& r_info);
583583
void MCScriptForeignHandlerInfoRelease(MCScriptForeignHandlerInfoRef p_info);
584584

585+
////////////////////////////////////////////////////////////////////////////////
586+
// Compiled modules are serialized to disk in the following format:
587+
//
588+
// byte magic[0] = 'L'
589+
// byte magic[1] = 'C'
590+
// byte version[0]
591+
// byte version[1]
592+
// <pickle of module struct>
593+
594+
// The module version will be incremented for every public release of the libscript
595+
// which occurs in which the module binary format changes.
596+
//
597+
// We will only aim to support module formats which have been released as final and
598+
// stable.
599+
//
600+
// The following constants keep track of, and should be updated to reflect the meaning
601+
// of each module version.
602+
603+
#define kMCScriptModuleVersion_8_0_0_DP_1 0
604+
#define kMCScriptModuleVersion_8_1_0_DP_2 1
605+
#define kMCScriptModuleVersion_9_0_0_DP_4 2
606+
#define kMCScriptCurrentModuleVersion kMCScriptModuleVersion_9_0_0_DP_4
607+
585608
////////////////////////////////////////////////////////////////////////////////
586609

587610
#endif

libscript/src/script-private.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -896,28 +896,4 @@ MCScriptBytecodeDecodeSignedArgument(uindex_t p_original_value)
896896

897897
////////////////////////////////////////////////////////////////////////////////
898898

899-
// Compiled modules are serialized to disk in the following format:
900-
//
901-
// byte magic[0] = 'L'
902-
// byte magic[1] = 'C'
903-
// byte version[0]
904-
// byte version[1]
905-
// <pickle of module struct>
906-
907-
// The module version will be incremented for every public release of the libscript
908-
// which occurs in which the module binary format changes.
909-
//
910-
// We will only aim to support module formats which have been released as final and
911-
// stable.
912-
//
913-
// The following constants keep track of, and should be updated to reflect the meaning
914-
// of each module version.
915-
916-
#define kMCScriptModuleVersion_8_0_0_DP_1 0
917-
#define kMCScriptModuleVersion_8_1_0_DP_2 1
918-
#define kMCScriptModuleVersion_9_0_0_DP_4 2
919-
#define kMCScriptCurrentModuleVersion kMCScriptModuleVersion_9_0_0_DP_4
920-
921-
////////////////////////////////////////////////////////////////////////////////
922-
923899
#endif

0 commit comments

Comments
 (0)