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

Commit 3df892f

Browse files
committed
libscript: Add MCScriptCreateModuleFromData().
Convenience function.
1 parent 747d66b commit 3df892f

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

libscript/include/libscript/script.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ bool MCScriptUnloadPackage(MCScriptPackageRef package);
162162
// Load a module from a stream.
163163
bool MCScriptCreateModuleFromStream(MCStreamRef stream, MCScriptModuleRef& r_module);
164164

165+
// Load a module from a blob
166+
MC_DLLEXPORT bool MCScriptCreateModuleFromData(MCDataRef data, MCScriptModuleRef & r_module);
167+
165168
// Lookup the module with the given name. Returns false if no such module exists.
166169
bool MCScriptLookupModule(MCNameRef name, MCScriptModuleRef& r_module);
167170

libscript/src/script-module.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <foundation-auto.h>
1919

2020
#include "libscript/script.h"
21+
#include <libscript/script-auto.h>
2122
#include "script-private.h"
2223

2324
#include <stddef.h>
@@ -502,6 +503,25 @@ bool MCScriptCreateModuleFromStream(MCStreamRef stream, MCScriptModuleRef& r_mod
502503
return true;
503504
}
504505

506+
MC_DLLEXPORT_DEF bool
507+
MCScriptCreateModuleFromData (MCDataRef data,
508+
MCScriptModuleRef & r_module)
509+
{
510+
MCAutoValueRefBase<MCStreamRef> t_stream;
511+
MCAutoScriptModuleRef t_module;
512+
513+
if (!MCMemoryInputStreamCreate (MCDataGetBytePtr (data),
514+
MCDataGetLength (data),
515+
&t_stream))
516+
return false;
517+
518+
if (!MCScriptCreateModuleFromStream (*t_stream, &t_module))
519+
return false;
520+
521+
r_module = MCScriptRetainModule (*t_module);
522+
return true;
523+
}
524+
505525
bool MCScriptLookupModule(MCNameRef p_name, MCScriptModuleRef& r_module)
506526
{
507527
for(MCScriptModule *t_module = s_modules; t_module != nil; t_module = t_module -> next_module)

0 commit comments

Comments
 (0)