Pass string_view instead of const char* to callback functions

This commit is contained in:
King_DuckZ 2022-04-28 22:55:22 +02:00
commit 6f4b0ce094
7 changed files with 63 additions and 42 deletions

View file

@ -18,6 +18,7 @@
#pragma once
#include "configuration.hpp"
#include "wrenpp/wren_types.hpp"
#include "error_type.hpp"
namespace wren {
@ -27,8 +28,8 @@ namespace wren {
class DefConfiguration : public Configuration {
public:
static void write_fn (VM*, const char* text);
static void error_fn (VM*, ErrorType, const char* module, int line, const char* msg);
static void write_fn (VM*, wren_string_t text);
static void error_fn (VM*, ErrorType, wren_string_t module, int line, wren_string_t msg);
static void* reallocate_fn(void* ptr, std::size_t size);
};
} //namespace wren

View file

@ -21,6 +21,7 @@
#include "error_type.hpp"
#include "handle.hpp"
#include "StringCRC32.hpp"
#include "wren_types.hpp"
#include <memory>
#include <tuple>
#include <utility>
@ -49,14 +50,14 @@ namespace wren {
namespace detail {
struct Callbacks {
void (*write_fn)(Configuration&, VM*, const char*) {nullptr};
void (*error_fn)(Configuration&, VM*, ErrorType, const char*, int, const char*) {nullptr};
void (*write_fn)(Configuration&, VM*, wren_string_t) {nullptr};
void (*error_fn)(Configuration&, VM*, ErrorType, wren_string_t, int, wren_string_t) {nullptr};
void* (*reallocate_fn)(void*, std::size_t) {nullptr};
const char* (*resolve_module_fn)(Configuration&, VM*, const char*, const char*) {nullptr};
char* (*load_module_fn)(Configuration&, VM*, const char*) {nullptr};
foreign_method_t (*foreign_method_fn)(Configuration&, VM*, const char*, const char*, bool, const char*) {nullptr};
foreign_class_t (*foreign_class_fn)(Configuration&, VM*, const char*, const char*) {nullptr};
void (*load_module_complete_fn)(Configuration&, VM*, const char*);
const char* (*resolve_module_fn)(Configuration&, VM*, wren_string_t, wren_string_t) {nullptr};
char* (*load_module_fn)(Configuration&, VM*, wren_string_t) {nullptr};
foreign_method_t (*foreign_method_fn)(Configuration&, VM*, wren_string_t, wren_string_t, bool, wren_string_t) {nullptr};
foreign_class_t (*foreign_class_fn)(Configuration&, VM*, wren_string_t, wren_string_t) {nullptr};
void (*load_module_complete_fn)(Configuration&, VM*, wren_string_t);
Configuration* config_obj {nullptr};
VM* owner {nullptr};
@ -125,13 +126,13 @@ namespace wren {
};
namespace detail {
define_method_info(write_fn, write, void, VM*, const char*);
define_method_info(error_fn, error, void, VM*, ErrorType, const char*, int, const char*);
define_method_info(write_fn, write, void, VM*, wren_string_t);
define_method_info(error_fn, error, void, VM*, ErrorType, wren_string_t, int, wren_string_t);
define_method_info(reallocate_fn, reallocate, void*, void*, std::size_t);
define_method_info(resolve_module_fn, resolve_module, const char*, const char*, const char*);
define_method_info(load_module_fn, load_module, char*, VM*, const char*);
define_method_info(foreign_method_fn, foreign_method, foreign_method_t, VM*, const char*, const char*, bool, const char*);
define_method_info(foreign_class_fn, foreign_class, foreign_class_t, VM*, const char*, const char*);
define_method_info(resolve_module_fn, resolve_module, wren_string_t, wren_string_t, wren_string_t);
define_method_info(load_module_fn, load_module, char*, VM*, wren_string_t);
define_method_info(foreign_method_fn, foreign_method, foreign_method_t, VM*, wren_string_t, wren_string_t, bool, wren_string_t);
define_method_info(foreign_class_fn, foreign_class, foreign_class_t, VM*, wren_string_t, wren_string_t);
template <typename T, typename F> struct AnyFunctionWrap;
template <typename T, typename R, typename... Args>

View file

@ -0,0 +1,22 @@
/* Copyright 2020-2022, Michele Santullo
* This file is part of wrenpp.
*
* Wrenpp is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Wrenpp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with wrenpp. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string_view>
namespace wren {
typedef std::string_view wren_string_t;
} //namespace wren