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

Commit 1c9a151

Browse files
committed
[[ Emscripten ]] Fix emscripten engine
This patch makes sure the emscripten engine works with the new appcode path changes and fixes an issue from the rework of library loading which meant it failed to run. In addition, it tweaks the libfoundation gyp file so the emscripten engine can be built on Mac; and adjusts the testgen script for a similar reason.
1 parent d381f32 commit 1c9a151

File tree

4 files changed

+46
-25
lines changed

4 files changed

+46
-25
lines changed

engine/src/em-main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ platform_main(int argc, char *argv[], char *envp[])
5555
{
5656
MCEmscriptenBootError("Core initialisation");
5757
}
58+
if (!MCSInitialize())
59+
{
60+
MCEmscriptenBootError("Core System initialisation");
61+
}
5862
if (!MCScriptInitialize())
5963
{
6064
MCEmscriptenBootError("LCB VM initialisation");

libfoundation/libfoundation.gyp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@
219219

220220
# Set java-related defines and includes
221221
[
222-
'host_os == "mac" and OS != "ios"',
222+
'host_os == "mac" and OS != "ios" and OS != "emscripten"',
223223
{
224224
'defines':
225225
[

libfoundation/src/system-library-emscripten.hpp

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,47 +23,64 @@
2323
* Emscripten Handle Class
2424
* ================================================================ */
2525

26-
/* The __MCSLibraryHandleEmscripten class is a specialization of the POSIX handle
27-
* implementation. It only supports manipulating the handle returned by passing
28-
* NULL to dlopen (which is the main executable) as loadable modules are not
29-
* currently used.
26+
/* The __MCSLibraryHandleEmscripten class is a dummy implementation which
27+
* notionally represents a handle to the main executable. It currently will
28+
* not find any symbols.
3029
*/
3130

32-
#include "system-library-posix.hpp"
33-
3431
#include <link.h>
3532
#include <sys/stat.h>
3633
#include <unistd.h>
3734

38-
class __MCSLibraryHandleEmscripten: public __MCSLibraryHandlePosix
35+
class __MCSLibraryHandleEmscripten
3936
{
4037
public:
38+
__MCSLibraryHandleEmscripten(void)
39+
{
40+
}
41+
42+
~__MCSLibraryHandleEmscripten(void)
43+
{
44+
}
45+
46+
bool IsDefined(void) const
47+
{
48+
return m_defined;
49+
}
50+
51+
bool IsEqualTo(const __MCSLibraryHandleEmscripten& p_other) const
52+
{
53+
return false;
54+
}
55+
56+
bool Hash(void) const
57+
{
58+
return MCHashPointer(nullptr);
59+
}
60+
4161
bool CreateWithNativePath(MCStringRef p_native_path)
4262
{
43-
return CreateWithAddress(nullptr);
63+
return false;
4464
}
4565

4666
bool CreateWithAddress(void *p_address)
4767
{
48-
void *t_dl_handle = dlopen(NULL,
49-
RTLD_LAZY);
50-
51-
if (t_dl_handle == nullptr)
52-
{
53-
/* TODO: Use dlerror */
54-
return __MCSLibraryThrowCreateWithAddressFailed(p_address);
55-
}
56-
57-
m_handle = t_dl_handle;
58-
68+
m_defined = true;
5969
return true;
6070
}
6171

62-
bool
63-
CopyNativePath(MCStringRef& r_native_path) const
72+
void *LookupSymbol(MCStringRef p_symbol) const
6473
{
65-
return MCSCommandLineGetName(r_native_path);
74+
return nullptr;
6675
}
76+
77+
bool CopyNativePath(MCStringRef& r_native_path) const
78+
{
79+
return MCStringCreateWithCString("<main>", r_native_path);
80+
}
81+
82+
private:
83+
bool m_defined = false;
6784
};
6885

6986
typedef class __MCSLibraryHandleEmscripten __MCSLibraryHandle;

tools/emscripten_testgen.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ cp -a ${test_src_dir} ${em_stack_dir}
4747
cp ${em_test_src_dir}/__boot.livecodescript ${em_test_build_dir}/standalone/boot/standalone/__boot.livecode
4848
# Copy in startup stack and make substitutions
4949
cp ${top_src_dir}/engine/rsrc/emscripten-startup-template.livecodescript ${em_test_build_dir}/standalone/boot/__startup.livecode
50-
sed -i -e"s,@BOOT_HASH@,${boot_hash}," ${em_test_build_dir}/standalone/boot/__startup.livecode
51-
sed -i -e"s,@ENGINE_VERSION@,${short_ver}," ${em_test_build_dir}/standalone/boot/__startup.livecode
50+
sed -i"foo" -e"s,@BOOT_HASH@,${boot_hash}," ${em_test_build_dir}/standalone/boot/__startup.livecode
51+
sed -i"foo" -e"s,@ENGINE_VERSION@,${short_ver}," ${em_test_build_dir}/standalone/boot/__startup.livecode
5252
# Create the standalone.zip file
5353
( cd ${em_test_build_dir}/standalone && zip -0qr ${em_test_build_dir}/standalone.zip * )

0 commit comments

Comments
 (0)