Added Wren scripting with module system 📚
Added Input pressed, released system Added interface button support with wren onclick callback
This commit is contained in:
38
Nuake/src/Scripting/Modules/EngineModule.h
Normal file
38
Nuake/src/Scripting/Modules/EngineModule.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
#include "wren.h"
|
||||
#include <string>
|
||||
#include <src/Core/Logger.h>
|
||||
#include "ScriptModule.h"
|
||||
#include <iostream>
|
||||
#include <wren.h>
|
||||
|
||||
namespace ScriptAPI
|
||||
{
|
||||
class EngineModule : public ScriptModule
|
||||
{
|
||||
std::string ModuleName = "Engine";
|
||||
std::string WrenAPI = "class Engine { \n"
|
||||
"foreign static Log(msg) \n"
|
||||
"}"
|
||||
"";
|
||||
|
||||
std::string GetModuleName() override
|
||||
{
|
||||
return "Engine";
|
||||
}
|
||||
|
||||
void RegisterModule(WrenVM* vm) override
|
||||
{
|
||||
RegisterMethod("Log(_)", (void*)Log);
|
||||
WrenInterpretResult result = wrenInterpret(vm, "main", WrenAPI.c_str());
|
||||
}
|
||||
|
||||
static void Log(WrenVM* vm)
|
||||
{
|
||||
std::string msg = wrenGetSlotString(vm, 1);
|
||||
Logger::Log(msg);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
27
Nuake/src/Scripting/Modules/ScriptModule.h
Normal file
27
Nuake/src/Scripting/Modules/ScriptModule.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <map>
|
||||
struct WrenVM;
|
||||
class ScriptModule
|
||||
{
|
||||
private:
|
||||
std::map<std::string, void*> Methods = std::map<std::string, void*>();
|
||||
|
||||
std::string WrenAPI;
|
||||
public:
|
||||
std::string ModuleName;
|
||||
virtual void RegisterModule(WrenVM*) = 0;
|
||||
virtual std::string GetModuleName() = 0;
|
||||
|
||||
void RegisterMethod(const std::string& signature, void* ptr)
|
||||
{
|
||||
Methods[signature] = ptr;
|
||||
}
|
||||
|
||||
void* GetMethodPointer(const std::string& signature)
|
||||
{
|
||||
return Methods[signature];
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user