WIP
This commit is contained in:
parent
995af6d2b6
commit
ec0c0b64e6
@ -1,14 +1,2 @@
|
||||
#pragma once
|
||||
#include "server/rccpp.h"
|
||||
|
||||
class Module : public RuntimeClass<Module> {
|
||||
CLASS_INTERNALS(Module)
|
||||
public:
|
||||
Module();
|
||||
~Module();
|
||||
RUNTIME_VIRTUAL int test_add(int a);
|
||||
|
||||
int m_sum;
|
||||
};
|
||||
|
||||
RUNTIME_EXPORT_CLASS(Module)
|
||||
|
11
src/server/internal_interface.h
Normal file
11
src/server/internal_interface.h
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
#include "server/rccpp.h"
|
||||
|
||||
class Module : public RuntimeClass<Module> {
|
||||
CLASS_INTERNALS(Module)
|
||||
public:
|
||||
Module();
|
||||
~Module();
|
||||
RUNTIME_VIRTUAL int test_add(int a, int b);
|
||||
};
|
||||
|
@ -64,12 +64,16 @@ void RCCPP_Compiler::build(const std::string &in_path, const std::string &out_pa
|
||||
std::string out_dir = c55fs::stripFilename(out_path);
|
||||
c55fs::CreateAllDirs(out_dir);
|
||||
|
||||
if(compile(in_path, out_path)) {
|
||||
if(!compile(in_path, out_path)) {
|
||||
std::cout << "Failed!" << std::endl;
|
||||
return;
|
||||
}
|
||||
std::cout << "Success!" << std::endl;
|
||||
|
||||
void *new_module = library_load(out_path.c_str());
|
||||
if(new_module == NULL){
|
||||
std::cout<<"Failed to load compiled library: "<<dlerror()<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
RCCPP_GetInterface GetInterface = (RCCPP_GetInterface)library_get_address(new_module, "rccpp_GetInterface");
|
||||
@ -116,9 +120,6 @@ void RCCPP_Compiler::build(const std::string &in_path, const std::string &out_pa
|
||||
}
|
||||
|
||||
changed_classes_.push_back(classname);
|
||||
} else {
|
||||
std::cout << "Failed!" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void *RCCPP_Compiler::construct(const char *name) {
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
// This is what you get when the RCCPP is not enabled
|
||||
#if !defined(RCCPP_ENABLED) && !defined(RCCPP)
|
||||
#define RUNTIME_EXPORT_CLASS(C)
|
||||
#define RUNTIME_EXPORT_MODULE(C)
|
||||
#define RUNTIME_VIRTUAL
|
||||
#endif
|
||||
|
||||
@ -33,7 +33,7 @@ struct RCCPP_Interface {
|
||||
#if defined(RCCPP) && !defined(RCCPP_ENABLED)
|
||||
#include <new>
|
||||
#define EXPORT __attribute__ ((visibility ("default")))
|
||||
#define RUNTIME_EXPORT_CLASS(C) \
|
||||
#define RUNTIME_EXPORT_MODULE(C) \
|
||||
extern "C" { \
|
||||
static void *rccpp_constructor() { return new C(); } \
|
||||
static void rccpp_destructor(void *c) { delete reinterpret_cast<C*>(c); } \
|
||||
@ -59,7 +59,7 @@ extern "C" { \
|
||||
#define RCCPP_MOVE "rccpp_move"
|
||||
#define RCCPP_CLASSNAME "rccpp_classname"
|
||||
|
||||
#define RUNTIME_EXPORT_CLASS(C)
|
||||
#define RUNTIME_EXPORT_MODULE(C)
|
||||
#define RUNTIME_VIRTUAL virtual
|
||||
|
||||
#include <vector>
|
||||
@ -76,17 +76,15 @@ struct RCCPP_Info {
|
||||
RCCPP_Destructor destructor;
|
||||
RCCPP_PlacementNew placement_new;
|
||||
size_t size;
|
||||
std::string classname;
|
||||
};
|
||||
|
||||
class RuntimeClassBase;
|
||||
|
||||
class RCCPP_Compiler {
|
||||
public:
|
||||
RCCPP_Compiler();
|
||||
|
||||
void build(const std::string &in_path, const std::string &out_path);
|
||||
|
||||
template<typename T> T *construct() { return (T*)construct(T::NAME); }
|
||||
void *construct(const char *name);
|
||||
|
||||
#if defined(RCCPP_USE_SINGLETON_NEWING)
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include "state.h"
|
||||
#include "rccpp.h"
|
||||
#include "config.h"
|
||||
#include "internal_interface.h"
|
||||
#include <iostream>
|
||||
|
||||
extern server::Config g_server_config;
|
||||
|
||||
@ -22,6 +24,10 @@ struct CState: public State
|
||||
{
|
||||
ss_ build_dst = g_server_config.rccpp_build_path + "/foo.o";
|
||||
m_compiler.build(path+"/server/main.cpp", build_dst);
|
||||
|
||||
Module *m = static_cast<Module*>(m_compiler.construct("Test1Module"));
|
||||
int a = m->test_add(1, 2);
|
||||
std::cout<<"a = "<<a<<std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1,15 +1,24 @@
|
||||
#include <core.h>
|
||||
#include "server/rccpp.h"
|
||||
|
||||
Module::Module()
|
||||
class Test1Module : public RuntimeClass<Test1Module> {
|
||||
CLASS_INTERNALS(Test1Module)
|
||||
public:
|
||||
Test1Module();
|
||||
~Test1Module();
|
||||
RUNTIME_VIRTUAL int test_add(int a, int b);
|
||||
};
|
||||
RUNTIME_EXPORT_MODULE(Test1Module)
|
||||
|
||||
Test1Module::Test1Module()
|
||||
{
|
||||
}
|
||||
|
||||
Module::~Module()
|
||||
Test1Module::~Test1Module()
|
||||
{
|
||||
}
|
||||
|
||||
int Module::test_add(int a)
|
||||
int Test1Module::test_add(int a, int b)
|
||||
{
|
||||
return a;
|
||||
return a + b;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user