-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathjumppad.cpp
More file actions
39 lines (32 loc) · 1.26 KB
/
jumppad.cpp
File metadata and controls
39 lines (32 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright (C) 2016-2018 Egor Pugin <[email protected]>
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include "jumppad.h"
#include <primitives/exceptions.h>
#include <primitives/preprocessor.h>
#include <boost/dll.hpp>
namespace sw
{
int jumppad_call(const path &module, const String &name, int version, const Strings &s)
{
auto n = STRINGIFY(SW_JUMPPAD_PREFIX) + name;
//n += "_" + std::to_string(version);
boost::dll::shared_library lib(module.u8string(),
boost::dll::load_mode::rtld_now | boost::dll::load_mode::rtld_global);
return lib.get<int(const Strings &)>(n.c_str())(s);
}
int jumppad_call(const Strings &s)
{
int i = 3;
if (s.size() < i++)
throw SW_RUNTIME_ERROR("No module name was provided");
if (s.size() < i++)
throw SW_RUNTIME_ERROR("No function name was provided");
if (s.size() < i++)
throw SW_RUNTIME_ERROR("No function version was provided");
// converting version to int is doubtful, but might help in removing leading zeroes (0002)
return jumppad_call(s[2], s[3], std::stoi(s[4]), Strings{s.begin() + 5, s.end()});
}
}