emscripten-core / emscripten-core/emscripten
ue4发布到html5平台后,如何通过网页上制作按钮与游戏进行通信?
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
.h file
#pragma once
#include "Kismet/BlueprintFunctionLibrary.h"
#include "CommunicationBridge.generated.h"
UCLASS()
class H5_API UCommunicationBridge : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
// C++ 函数,供 JavaScript 调用
UFUNCTION(BlueprintCallable, Category = "Communication")
static void JsFunction();
// C++ 函数,接收从 JavaScript 传递过来的参数
UFUNCTION(BlueprintCallable, Category = "Communication")
static void ReceiveMessageFromJS(const FString& Message);
// C++ 函数,供 JavaScript 调用并返回结果
UFUNCTION(BlueprintCallable, Category = "Communication")
static int AddNumbers(int A, int B);
// C++ 函数,向 JavaScript 发送消息
UFUNCTION(BlueprintCallable, Category = "Communication")
static void SendMessageToJS(const FString& Message);
};
.cpp file
#include "emscripten/emscripten.h"
#include "CommunicationBridge.h"
void UCommunicationBridge::JsFunction()
{
// Call the declared JavaScript function
emscripten_run_script("console.log('C++ function called from JavaScript!');");
}
void UCommunicationBridge::ReceiveMessageFromJS(const FString& Message)
{
const char* MessageChar = TCHAR_TO_UTF8(*Message);
FString Script = FString::Printf(TEXT("console.log('Message from JavaScript: %s');"), MessageChar);
emscripten_run_script(TCHAR_TO_UTF8(*Script));
}
int UCommunicationBridge::AddNumbers(int A, int B)
{
FString Script = FString::Printf(TEXT("return %d + %d;"), A, B);
int Result = emscripten_run_script_int(TCHAR_TO_UTF8(*Script));
return Result;
}
void UCommunicationBridge::SendMessageToJS(const FString& Message)
{
const char* MessageChar = TCHAR_TO_UTF8(*Message);
emscripten_run_script(MessageChar);
}
The above are the header files and source files, but the compilation fails, and the following error always appears:
严重性 代码 说明 项目 文件 行 禁止显示状态
错误(活动) E1389 重新声明无法将 dllexport/dllimport 添加到 "abort" (已声明 所在行数:46,所属文件:"D:\ue-4.27-html5-es3\Engine\Platforms\HTML5\Build\emsdk\emsdk-3.1.47\upstream\emscripten\cache\sysroot\include\stdlib.h") H5 C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt_terminate.h 28
Please help me see how this issue is solved, thanks a lot!
Contributor guide
Assessment
This issue has not been assessed yet.