From f4679440951ec44e66ba869b9aefdf102fbbf0be Mon Sep 17 00:00:00 2001 From: jyelon Date: Thu, 24 Feb 2022 02:17:41 -0500 Subject: [PATCH] Migrated engine to using dlmalloc through eng:: --- luprex/core/Makefile | 2 +- luprex/core/badmem.sh | 16 +++ luprex/core/cpp/animqueue.cpp | 45 ++++---- luprex/core/cpp/animqueue.hpp | 37 +++---- luprex/core/cpp/debugcollector.cpp | 8 +- luprex/core/cpp/debugcollector.hpp | 12 +- luprex/core/cpp/drivenengine.cpp | 28 ++--- luprex/core/cpp/drivenengine.hpp | 52 ++++----- luprex/core/cpp/driver-common.cpp | 60 +++++----- luprex/core/cpp/driver-linux.cpp | 18 +-- luprex/core/cpp/driver-mingw.cpp | 26 ++--- luprex/core/cpp/driver-util.cpp | 15 +-- luprex/core/cpp/driver-util.hpp | 6 +- .../cpp/{drivertests.cpp => eng-tests.cpp} | 16 +-- .../cpp/{drivertests.hpp => eng-tests.hpp} | 0 luprex/core/cpp/gui.cpp | 14 +-- luprex/core/cpp/gui.hpp | 18 +-- luprex/core/cpp/idalloc.cpp | 17 ++- luprex/core/cpp/idalloc.hpp | 10 +- luprex/core/cpp/invocation.cpp | 16 +-- luprex/core/cpp/invocation.hpp | 16 +-- luprex/core/cpp/lpxclient.cpp | 6 +- luprex/core/cpp/lpxserver.cpp | 6 +- luprex/core/cpp/luaconsole.cpp | 16 +-- luprex/core/cpp/luaconsole.hpp | 12 +- luprex/core/cpp/luastack.cpp | 38 +++---- luprex/core/cpp/luastack.hpp | 28 ++--- luprex/core/cpp/planemap.cpp | 13 ++- luprex/core/cpp/planemap.hpp | 22 ++-- luprex/core/cpp/pprint.cpp | 17 +-- luprex/core/cpp/pprint.hpp | 5 +- luprex/core/cpp/printbuffer.cpp | 22 ++-- luprex/core/cpp/printbuffer.hpp | 9 +- luprex/core/cpp/sched.cpp | 8 +- luprex/core/cpp/sched.hpp | 6 +- luprex/core/cpp/source.cpp | 82 +++++++------- luprex/core/cpp/source.hpp | 8 +- luprex/core/cpp/streambuffer.cpp | 36 +++--- luprex/core/cpp/streambuffer.hpp | 20 ++-- luprex/core/cpp/table.cpp | 2 +- luprex/core/cpp/textgame.cpp | 4 +- luprex/core/cpp/two-mallocs.cpp | 2 +- luprex/core/cpp/two-mallocs.hpp | 43 +++++--- luprex/core/cpp/util.cpp | 104 +++++++++--------- luprex/core/cpp/util.hpp | 84 +++++++------- luprex/core/cpp/world-accessor.cpp | 16 +-- luprex/core/cpp/world-core.cpp | 30 ++--- luprex/core/cpp/world-difftab.cpp | 14 +-- luprex/core/cpp/world-diffxmit.cpp | 8 +- luprex/core/cpp/world-pairtab.cpp | 4 +- luprex/core/cpp/world-testing.cpp | 50 ++++----- luprex/core/cpp/world.hpp | 50 ++++----- luprex/core/wrap/wrap-deque.hpp | 2 +- luprex/core/wrap/wrap-map.hpp | 2 +- luprex/core/wrap/wrap-set.hpp | 2 +- luprex/core/wrap/wrap-sstream.hpp | 6 +- luprex/core/wrap/wrap-string.hpp | 2 +- luprex/core/wrap/wrap-unordered-map.hpp | 2 +- luprex/core/wrap/wrap-unordered-set.hpp | 2 +- luprex/core/wrap/wrap-utility.hpp | 4 + luprex/core/wrap/wrap-vector.hpp | 2 +- 61 files changed, 631 insertions(+), 590 deletions(-) create mode 100755 luprex/core/badmem.sh rename luprex/core/cpp/{drivertests.cpp => eng-tests.cpp} (93%) rename luprex/core/cpp/{drivertests.hpp => eng-tests.hpp} (100%) diff --git a/luprex/core/Makefile b/luprex/core/Makefile index 3a333203..1ee9894f 100644 --- a/luprex/core/Makefile +++ b/luprex/core/Makefile @@ -93,7 +93,7 @@ CORE_OBJ_FILES=\ obj/textgame.o\ obj/lpxserver.o\ obj/lpxclient.o\ - obj/drivertests.o\ + obj/eng-tests.o\ obj/printbuffer.o\ obj/driver-util.o\ obj/$(DRIVER).o\ diff --git a/luprex/core/badmem.sh b/luprex/core/badmem.sh new file mode 100755 index 00000000..e21ba3d2 --- /dev/null +++ b/luprex/core/badmem.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +grep std::string cpp/* +grep std::vector cpp/* +grep std::map cpp/* +grep 'std::set<' cpp/* +grep std::unordered_map cpp/* +grep std::unordered_set cpp/* +grep std::deque cpp/* +grep std::ostringstream cpp/* +grep std::ostream cpp/* +grep std::unique_ptr cpp/* +grep std::shared_ptr cpp/* + +grep std::cerr cpp/* +grep std::cout cpp/* diff --git a/luprex/core/cpp/animqueue.cpp b/luprex/core/cpp/animqueue.cpp index 44bc64cd..afbe47f3 100644 --- a/luprex/core/cpp/animqueue.cpp +++ b/luprex/core/cpp/animqueue.cpp @@ -1,12 +1,13 @@ +#include "wrap-sstream.hpp" +#include "wrap-map.hpp" #include "animqueue.hpp" -#include "wrap-sstream.hpp" -#include -#include "wrap-map.hpp" -#include #include "luastack.hpp" #include "streambuffer.hpp" +#include +#include + AnimStep::AnimStep() { clear(); } @@ -24,7 +25,7 @@ void AnimStep::clear() { plane_ = ""; } -void AnimStep::set_action(const std::string &act) { +void AnimStep::set_action(const eng::string &act) { action_ = act; } @@ -53,12 +54,12 @@ void AnimStep::set_xyz(const util::XYZ &xyz) { xyz_ = xyz; } -void AnimStep::set_graphic(const std::string &g) { +void AnimStep::set_graphic(const eng::string &g) { bits_ |= HAS_GRAPHIC; graphic_ = g; } -void AnimStep::set_plane(const std::string &p) { +void AnimStep::set_plane(const eng::string &p) { bits_ |= HAS_PLANE; plane_ = p; } @@ -145,7 +146,7 @@ void AnimStep::read_from(StreamBuffer *sb) { } -void AnimStep::from_lua_store_string(lua_State *L, int idx, std::string *target, int16_t bits, const char *name) { +void AnimStep::from_lua_store_string(lua_State *L, int idx, eng::string *target, int16_t bits, const char *name) { if ((bits_ & bits)||(*target != "")) { luaL_error(L, "specified %s twice", name); } @@ -179,7 +180,7 @@ void AnimStep::from_lua(lua_State *L, int idx, bool ignex, const AnimStep &qback if (!LS.isstring(key)) { luaL_error(L, "animation specs must be key/value where key is a string"); } - std::string skey = LS.ckstring(key); + eng::string skey = LS.ckstring(key); if (skey == "action") { from_lua_store_string(L, value.index(), &action_, 0, "action"); } else if (skey == "graphic") { @@ -257,8 +258,8 @@ bool AnimStep::echoes(const AnimStep &prev) const { return true; } -std::string AnimStep::debug_string() const { - std::ostringstream oss; +eng::string AnimStep::debug_string() const { + eng::ostringstream oss; oss << "id=" << id(); oss << " action=" << action(); if (has_plane()) { @@ -283,16 +284,16 @@ std::string AnimStep::debug_string() const { } -bool AnimStep::from_string(const std::string &config) { +bool AnimStep::from_string(const eng::string &config) { clear(); util::StringVec parts = util::split(config, ' '); for (int i = 0; i < int(parts.size()); i++) { - const std::string &part = parts[i]; + const eng::string &part = parts[i]; if (part == "") continue; util::StringVec lr = util::split(part, '='); if (lr.size() != 2) return false; - const std::string &key = lr[0]; - const std::string &val = lr[1]; + const eng::string &key = lr[0]; + const eng::string &val = lr[1]; if (key == "action") { action_ = val; } else if (key == "id") { @@ -366,7 +367,7 @@ void AnimQueue::full_clear_and_set_limit(int n) { version_number_ = version_autoinc_ ? 1 : 0; } -void AnimQueue::clear(const std::string &plane) { +void AnimQueue::clear(const eng::string &plane) { steps_.clear(); steps_.emplace_back(); steps_.front().set_plane(plane); @@ -427,16 +428,16 @@ bool AnimQueue::valid() const { return true; } -std::string AnimQueue::steps_debug_string() const { - std::ostringstream oss; +eng::string AnimQueue::steps_debug_string() const { + eng::ostringstream oss; for (int i = 0; i < int(size()); i++) { oss << nth(i).debug_string() << "; "; } return oss.str(); } -std::string AnimQueue::full_debug_string() const { - std::ostringstream oss; +eng::string AnimQueue::full_debug_string() const { + eng::ostringstream oss; for (int i = 0; i < int(size()); i++) { oss << nth(i).debug_string() << "; "; } @@ -504,7 +505,7 @@ bool AnimQueue::diff(const AnimQueue &auth, StreamBuffer *sb) const { } // Index the remaining elements by id. - std::map index; + eng::map index; for (int i = 1; i < int(steps_.size()); i++) { index[steps_[i].id_] = i; } @@ -538,7 +539,7 @@ void AnimQueue::patch(StreamBuffer *sb, DebugCollector *dbc) { size_limit_ = sb->read_uint8(); // Decode the diff, stop at eof. - std::deque old = std::move(steps_); + eng::deque old = std::move(steps_); steps_.clear(); for (int i = 0; i < len; i++) { uint8_t index = sb->read_uint8(); diff --git a/luprex/core/cpp/animqueue.hpp b/luprex/core/cpp/animqueue.hpp index de551aff..593e5869 100644 --- a/luprex/core/cpp/animqueue.hpp +++ b/luprex/core/cpp/animqueue.hpp @@ -48,15 +48,14 @@ #include "wrap-set.hpp" #include "wrap-string.hpp" #include "wrap-deque.hpp" -#include "wrap-ostream.hpp" #include "wrap-unordered-map.hpp" - -#include +#include "wrap-ostream.hpp" #include "streambuffer.hpp" #include "debugcollector.hpp" #include "util.hpp" +#include class AnimStep { friend class AnimQueue; @@ -78,14 +77,14 @@ public: int64_t id() const { return id_; } int bits() const { return bits_; } - const std::string &action() const { return action_; } + const eng::string &action() const { return action_; } double facing() const { return facing_; } float x() const { return xyz_.x; } float y() const { return xyz_.y; } float z() const { return xyz_.z; } const util::XYZ &xyz() const { return xyz_; } - const std::string &graphic() const { return graphic_; } - const std::string &plane() const { return plane_; } + const eng::string &graphic() const { return graphic_; } + const eng::string &plane() const { return plane_; } bool has_facing() const { return bits_ & HAS_FACING; } bool has_x() const { return bits_ & HAS_X; } @@ -95,14 +94,14 @@ public: bool has_graphic() const { return bits_ & AnimStep::HAS_GRAPHIC; } bool has_plane() const { return bits_ & AnimStep::HAS_PLANE; } - void set_action(const std::string &action); + void set_action(const eng::string &action); void set_facing(float f); void set_x(float f); void set_y(float f); void set_z(float z); void set_xyz(const util::XYZ &xyz); - void set_graphic(const std::string &g); - void set_plane(const std::string &p); + void set_graphic(const eng::string &g); + void set_plane(const eng::string &p); void clear(); @@ -147,22 +146,22 @@ public: bool echoes(const AnimStep &prev) const; // Convert to a string for debugging purposes. - std::string debug_string() const; + eng::string debug_string() const; // Convert a string to an animstep (for testing only). - bool from_string(const std::string &s); + bool from_string(const eng::string &s); private: int64_t id_; int16_t bits_; - std::string action_; + eng::string action_; float facing_; util::XYZ xyz_; - std::string graphic_; - std::string plane_; + eng::string graphic_; + eng::string plane_; - void from_lua_store_string(lua_State *L, int idx, std::string *target, int16_t bits, const char *name); + void from_lua_store_string(lua_State *L, int idx, eng::string *target, int16_t bits, const char *name); void from_lua_store_number(lua_State *L, int idx, float *target, float offset, int16_t bits, const char *name); }; @@ -186,7 +185,7 @@ public: void add(int64_t id, const AnimStep &step); // Clear and set the plane. - void clear(const std::string &plane); + void clear(const eng::string &plane); // Serialize or deserialize to a StreamBuffer // @@ -222,15 +221,15 @@ public: bool valid() const; // Convert to a string for debugging purposes. - std::string steps_debug_string() const; - std::string full_debug_string() const; + eng::string steps_debug_string() const; + eng::string full_debug_string() const; // Convert to a private: bool version_autoinc_; int32_t size_limit_; - std::deque steps_; + eng::deque steps_; int64_t version_number_; // Called whenever the animation queue is mutated. diff --git a/luprex/core/cpp/debugcollector.cpp b/luprex/core/cpp/debugcollector.cpp index 70b8667d..4d482612 100644 --- a/luprex/core/cpp/debugcollector.cpp +++ b/luprex/core/cpp/debugcollector.cpp @@ -8,7 +8,7 @@ void DebugCollector::flush() { if (need_flush_) { - std::string str = oss_.str(); + eng::string str = oss_.str(); if (!str.empty()) { if (is_regular_) n_regular_ += 1; lines_.push_back(str); @@ -21,7 +21,7 @@ void DebugCollector::flush() { DebugCollector::DebugCollector() : n_regular_(0), need_flush_(false), is_regular_(true), active_(false) { } -DebugCollector::DebugCollector(const std::string &targets) +DebugCollector::DebugCollector(const eng::string &targets) : n_regular_(0), need_flush_(false), is_regular_(true), active_(false) { targets_ = util::split(targets, ','); std::sort(targets_.begin(), targets_.end()); @@ -56,9 +56,9 @@ bool DebugCollector::do_header() { return true; } -void DebugCollector::dump(std::ostream &os) { +void DebugCollector::dump(eng::ostream &os) { flush(); - for (const std::string &line : lines_) { + for (const eng::string &line : lines_) { os << line << std::endl; } } diff --git a/luprex/core/cpp/debugcollector.hpp b/luprex/core/cpp/debugcollector.hpp index 6ded7da6..8768b427 100644 --- a/luprex/core/cpp/debugcollector.hpp +++ b/luprex/core/cpp/debugcollector.hpp @@ -4,8 +4,8 @@ #include "wrap-vector.hpp" #include "wrap-string.hpp" #include "wrap-memory.hpp" -#include "wrap-ostream.hpp" #include "wrap-sstream.hpp" +#include "wrap-ostream.hpp" class DebugCollector { private: @@ -14,8 +14,8 @@ private: // The flag 'need_flush_' is true if the stringstream contains // an extra line. In that case, is_regular_ indicates whether // the extra line is a header or a regular line. - std::vector lines_; - std::vector targets_; + eng::vector lines_; + eng::vector targets_; int n_regular_; bool need_flush_; bool is_regular_; @@ -23,12 +23,12 @@ private: void flush(); bool use(const char *target); public: - std::ostringstream oss_; + eng::ostringstream oss_; DebugCollector(); - DebugCollector(const std::string &targets); + DebugCollector(const eng::string &targets); bool do_header(); bool do_line(); - void dump(std::ostream &os); + void dump(eng::ostream &os); friend class DebugBlock; }; diff --git a/luprex/core/cpp/drivenengine.cpp b/luprex/core/cpp/drivenengine.cpp index 140093a0..8439ffa8 100644 --- a/luprex/core/cpp/drivenengine.cpp +++ b/luprex/core/cpp/drivenengine.cpp @@ -7,14 +7,14 @@ #include "drivenengine.hpp" -static std::vector> makers; +static eng::vector> makers; void DrivenEngine::register_maker(const char *kind, DrivenEngineMaker maker) { - std::string skind(kind); + eng::string skind(kind); makers.push_back(std::make_pair(skind, maker)); } -void DrivenEngine::print_usage(std::ostream &strm, const char *progname) { +void DrivenEngine::print_usage(eng::ostream &strm, const char *progname) { strm << "Usage: " << progname << " " << std::endl; for (const auto &mpair : makers) { strm << " Mode can be: " << mpair.first << std::endl; @@ -30,7 +30,7 @@ UniqueDrivenEngine DrivenEngine::make(const char *kind) { return nullptr; } -Channel::Channel(DrivenEngine *de, int chid, int port, const std::string &target, bool stop) { +Channel::Channel(DrivenEngine *de, int chid, int port, const eng::string &target, bool stop) { chid_ = chid; port_ = port; closed_ = false; @@ -73,14 +73,14 @@ void Channel::echo_command() { } // Echo the new part. - std::string newpart = desired_command_.substr(current_command_.size()); + eng::string newpart = desired_command_.substr(current_command_.size()); if (newpart != "") { sb_drvout_->write_bytes(newpart); current_command_ = desired_command_; } } -void Channel::set_prompt(const std::string &p) { +void Channel::set_prompt(const eng::string &p) { desired_prompt_ = p; } @@ -92,7 +92,7 @@ void Channel::feed_readline(int nbytes, const char *bytes) { // Otherwise, crlf produces two newlines. } else if ((c == '\r') || (c == '\n')) { echo_command(); - sb_drvout_->write_bytes(std::string(" \n")); + sb_drvout_->write_bytes(eng::string(" \n")); sb_in_->write_bytes(desired_command_); sb_in_->write_uint8('\n'); desired_command_ = ""; @@ -157,7 +157,7 @@ double DrivenEngine::get_clock() { return clock_; } -SharedChannel DrivenEngine::new_outgoing_channel(const std::string &target) { +SharedChannel DrivenEngine::new_outgoing_channel(const eng::string &target) { int chid = find_unused_chid(); new_outgoing_.push_back(chid); SharedChannel result = std::make_shared(this, chid, 0, target, stop_driver_); @@ -196,11 +196,11 @@ void DrivenEngine::stop_driver() { } } -const std::vector &DrivenEngine::drv_get_listen_ports() const { +const eng::vector &DrivenEngine::drv_get_listen_ports() const { return listen_ports_; } -const std::vector &DrivenEngine::drv_get_new_outgoing() const { +const eng::vector &DrivenEngine::drv_get_new_outgoing() const { return new_outgoing_; } @@ -208,7 +208,7 @@ void DrivenEngine::drv_clear_new_outgoing() { new_outgoing_.clear(); } -const std::string &DrivenEngine::drv_get_target(int chid) const { +const eng::string &DrivenEngine::drv_get_target(int chid) const { return get_chid(chid)->target_; } @@ -241,7 +241,7 @@ void DrivenEngine::drv_recv_incoming(int chid, int nbytes, const char *bytes) { } } -void DrivenEngine::drv_notify_close(int chid, std::string_view err) { +void DrivenEngine::drv_notify_close(int chid, eng::string_view err) { Channel *ch = get_chid(chid); ch->closed_ = true; ch->error_ = err; @@ -260,11 +260,11 @@ void DrivenEngine::drv_clear_lua_source() { rescan_lua_source_ = false; } -void DrivenEngine::drv_add_lua_source(std::string_view fn, std::string_view data) { +void DrivenEngine::drv_add_lua_source(eng::string_view fn, eng::string_view data) { if (lua_source_ == nullptr) { lua_source_.reset(new util::LuaSourceVec); } - lua_source_->emplace_back(std::string(fn), std::string(data)); + lua_source_->emplace_back(eng::string(fn), eng::string(data)); } void DrivenEngine::drv_invoke_event_init(int argc, char *argv[]) { diff --git a/luprex/core/cpp/drivenengine.hpp b/luprex/core/cpp/drivenengine.hpp index 64750540..3b5fd9ad 100644 --- a/luprex/core/cpp/drivenengine.hpp +++ b/luprex/core/cpp/drivenengine.hpp @@ -101,7 +101,7 @@ #include "streambuffer.hpp" class DrivenEngine; -using UniqueDrivenEngine = std::unique_ptr; +using UniqueDrivenEngine = eng::unique_ptr; using DrivenEngineMaker = UniqueDrivenEngine (*)(); class Channel { @@ -120,7 +120,7 @@ public: int port() { return port_; } // If this is an outgoing socket connection, get the target host. - const std::string &target() { return target_; } + const eng::string &target() { return target_; } // True if the remote closed the connection, or a failure occurred. // @@ -131,18 +131,18 @@ public: // If this is an empty string, there is no error. If this is set, // then the channel is also closed. // - std::string error() const { return error_; } + eng::string error() const { return error_; } // Set the prompt for readline mode. // - void set_prompt(const std::string &prompt); + void set_prompt(const eng::string &prompt); // Do not construct your own Channels. Instead, // use methods of class DrivenEngine like new_outgoing_channel. // Channels are referenced by shared_ptr. You can // release your shared_ptr at any time. // - Channel(DrivenEngine *de, int chid, int port, const std::string &target, bool stop); + Channel(DrivenEngine *de, int chid, int port, const eng::string &target, bool stop); ~Channel() {}; private: @@ -162,31 +162,31 @@ private: int chid_; // These are the in/out buffers presented to the user. - std::shared_ptr sb_in_; - std::shared_ptr sb_out_; + eng::shared_ptr sb_in_; + eng::shared_ptr sb_out_; // If this is stdio, we inject tty echoes into the output stream. // This buffer holds the users output interleaved with the tty echoes. // In any other channel, this is just another pointer to sb_out. - std::shared_ptr sb_drvout_; + eng::shared_ptr sb_drvout_; int port_; bool closed_; - std::string error_; - std::string target_; + eng::string error_; + eng::string target_; bool stop_driver_; // Readline stuff. Only used on channel 0 (stdio). - std::string desired_command_; - std::string current_command_; - std::string desired_prompt_; - std::string current_prompt_; + eng::string desired_command_; + eng::string current_command_; + eng::string desired_prompt_; + eng::string current_prompt_; char readline_lastc_; friend class DrivenEngine; }; -using SharedChannel = std::shared_ptr; +using SharedChannel = eng::shared_ptr; class DrivenEngine { public: @@ -228,7 +228,7 @@ public: // actually opening the connection and relaying data into the channel using // drv_get_target, drv_peek_outgoing, drv_sent_outgoing, drv_recv_incoming. // - SharedChannel new_outgoing_channel(const std::string &target); + SharedChannel new_outgoing_channel(const eng::string &target); // Create a new channel from any pending incoming connection. If there is no // incoming connection, returns nullptr. @@ -254,7 +254,7 @@ public: // Obtain the output buffer of the stdio channel as an ostream. // - std::ostream &stdostream() { return get_stdio_channel()->out()->ostream(); } + eng::ostream &stdostream() { return get_stdio_channel()->out()->ostream(); } // Fetches the lua source, and takes ownership of it. The DrivenEngine // no longer contains the source after calling this. @@ -288,13 +288,13 @@ public: // Get a list of all the listening ports. The driver is expected // to fetch this set shortly after the event_init callback is invoked. // - const std::vector &drv_get_listen_ports() const; + const eng::vector &drv_get_listen_ports() const; // Get a list of all recently-opened channels that were created using // drv_new_outgoing_channel. The driver should initiate outgoing // connections for these channels. // - const std::vector &drv_get_new_outgoing() const; + const eng::vector &drv_get_new_outgoing() const; // Clear the list of recently-opened channels that were created using // drv_new_outgoing_channel. @@ -306,7 +306,7 @@ public: // is supposed to be talking to. Non-socket channels and incoming channels // have empty targets. // - const std::string &drv_get_target(int chid) const; + const eng::string &drv_get_target(int chid) const; // Return true if the outgoing buffer is empty. // @@ -343,7 +343,7 @@ public: // delete it. Closing a channel prevents it from showing up in // 'drv_list_channels'. // - void drv_notify_close(int chid, std::string_view err); + void drv_notify_close(int chid, eng::string_view err); // Notify the DrivenEngine that somebody connected to an incoming port. // This will cause the DrivenEngine to allocate a new channel and put the @@ -361,7 +361,7 @@ public: // Set the lua source code. The driver is expected to read the lua source // code and store it (using this function) once before invoking // - void drv_add_lua_source(std::string_view fn, std::string_view data); + void drv_add_lua_source(eng::string_view fn, eng::string_view data); // Invoke the init or update event. // @@ -417,7 +417,7 @@ public: static void register_maker(const char *kind, DrivenEngineMaker maker); - static void print_usage(std::ostream &strm, const char *progname); + static void print_usage(eng::ostream &strm, const char *progname); static UniqueDrivenEngine make(const char *kind); @@ -433,10 +433,10 @@ private: SharedChannel channels_[MAX_CHAN]; int next_unused_chid_; SharedChannel stdio_channel_; - std::vector accepted_channels_; - std::vector new_outgoing_; + eng::vector accepted_channels_; + eng::vector new_outgoing_; util::LuaSourcePtr lua_source_; - std::vector listen_ports_; + eng::vector listen_ports_; bool rescan_lua_source_; double clock_; bool stop_driver_; diff --git a/luprex/core/cpp/driver-common.cpp b/luprex/core/cpp/driver-common.cpp index 322303ae..19e97c64 100644 --- a/luprex/core/cpp/driver-common.cpp +++ b/luprex/core/cpp/driver-common.cpp @@ -2,8 +2,8 @@ #define CHBUF_SIZE (256*1024) #define POLLVEC_SIZE (DrivenEngine::MAX_CHAN+1) -static std::unique_ptr chbuf; -static std::unique_ptr pollvec; +static drv::unique_ptr chbuf; +static drv::unique_ptr pollvec; static MonoClock monoclock; @@ -30,37 +30,37 @@ static void allocate_buffers() { pollvec.reset(new struct pollfd[POLLVEC_SIZE]); } -static void if_error_print_and_exit(const std::string &str) { +static void if_error_print_and_exit(const drv::string &str) { if (!str.empty()) { std::cerr << std::endl << "error: " << str << std::endl; exit(1); } } -static std::string_view read_file(const char *fn, char *buf, int bufsize, std::string &err) { +static drv::string_view read_file(const char *fn, char *buf, int bufsize, drv::string &err) { FILE *f = fopen(fn, "r"); if (f == 0) { - err = std::string("cannot read file") + fn; + err = drv::string("cannot read file") + fn; buf[0] = 0; - return std::string_view(buf, 0); + return drv::string_view(buf, 0); } int nread = fread(buf, 1, bufsize, f); if (nread < 0) { - err = std::string("cannot read file: ") + fn; + err = drv::string("cannot read file: ") + fn; buf[0] = 0; - return std::string_view(buf, 0); + return drv::string_view(buf, 0); } if (nread == bufsize) { - err = std::string("file too large: ") + fn; + err = drv::string("file too large: ") + fn; buf[0] = 0; - return std::string_view(buf, 0); + return drv::string_view(buf, 0); } err = ""; - return std::string_view(buf, nread); + return drv::string_view(buf, nread); } -static SSL_CTX *new_ssl_context(bool server_cert, bool root_certs, std::string_view require_cert) { +static SSL_CTX *new_ssl_context(bool server_cert, bool root_certs, drv::string_view require_cert) { SSL_CTX *ctx = SSL_CTX_new(TLS_method()); SSL_CTX_set_mode(ctx, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER); SSL_CTX_set_mode(ctx, SSL_MODE_ENABLE_PARTIAL_WRITE); @@ -74,12 +74,12 @@ static SSL_CTX *new_ssl_context(bool server_cert, bool root_certs, std::string_v return ctx; } -static std::string err_print_errors_str() { +static drv::string err_print_errors_str() { BIO *bio = BIO_new(BIO_s_mem()); ERR_print_errors(bio); char *buf; size_t len = BIO_get_mem_data(bio, &buf); - std::string ret(buf, len); + drv::string ret(buf, len); BIO_free(bio); return ret; } @@ -133,8 +133,8 @@ public: }; DrivenEngine *driven_; - std::vector chans_; - std::map listen_sockets_; + drv::vector chans_; + drv::map listen_sockets_; bool read_console_recently_; SSL_CTX *ssl_ctx_with_root_certs_; @@ -143,10 +143,10 @@ public: void handle_listen_ports() { - const std::vector &listenports = driven_->drv_get_listen_ports(); + const auto &listenports = driven_->drv_get_listen_ports(); for (int port : listenports) { if (listen_sockets_.find(port) == listen_sockets_.end()) { - std::string err; + drv::string err; SOCKET sock = listen_on_port(port, err); if_error_print_and_exit(err); assert(sock != INVALID_SOCKET); @@ -157,21 +157,21 @@ public: void handle_lua_source() { if (driven_->drv_get_rescan_lua_source()) { - std::string err; - std::string_view ctrl = read_file("lua/control.lst", chbuf.get(), CHBUF_SIZE, err); + drv::string err; + drv::string_view ctrl = read_file("lua/control.lst", chbuf.get(), CHBUF_SIZE, err); if_error_print_and_exit(err); - std::vector names = drv::parse_control_lst(ctrl); + drv::vector names = drv::parse_control_lst(ctrl); driven_->drv_clear_lua_source(); - for (const std::string &str : names) { - std::string lfn = std::string("lua/") + str; - std::string_view data = read_file(lfn.c_str(), chbuf.get(), CHBUF_SIZE, err); + for (const drv::string &str : names) { + drv::string lfn = drv::string("lua/") + str; + drv::string_view data = read_file(lfn.c_str(), chbuf.get(), CHBUF_SIZE, err); if_error_print_and_exit(err); driven_->drv_add_lua_source(str, data); } } } - void close_channel(ChanInfo &chan, std::string_view err) { + void close_channel(ChanInfo &chan, drv::string_view err) { // std::cerr << "Closing channel " << chan.chid << std::endl; assert(chan.state != CHAN_INACTIVE); // Close and release the SSL channel. @@ -253,9 +253,9 @@ public: } void handle_new_outgoing_sockets() { - const std::vector &chans = driven_->drv_get_new_outgoing(); + const auto &chans = driven_->drv_get_new_outgoing(); for (int chid : chans) { - std::string err; + drv::string err; SOCKET sock = open_connection(driven_->drv_get_target(chid), err); if (sock == INVALID_SOCKET) { driven_->drv_notify_close(chid, err); @@ -270,7 +270,7 @@ public: } void accept_connection(int port, SOCKET sock) { - std::string err; + drv::string err; SOCKET socket = accept_on_socket(sock, err); if_error_print_and_exit(err); if (socket != INVALID_SOCKET) { @@ -281,7 +281,7 @@ public: } void advance_plaintext(ChanInfo &chan) { - std::string err; + drv::string err; // If the channel has no outgoing bytes and has been released, // just close it. @@ -418,7 +418,7 @@ public: void handle_socket_input_output() { - std::string err; + drv::string err; int mstimeout = read_console_recently_ ? 100 : 1000; // Peek output buffers and determine channel release flags. diff --git a/luprex/core/cpp/driver-linux.cpp b/luprex/core/cpp/driver-linux.cpp index 333362af..4faa5ed6 100644 --- a/luprex/core/cpp/driver-linux.cpp +++ b/luprex/core/cpp/driver-linux.cpp @@ -9,7 +9,7 @@ #include "textgame.hpp" #include "lpxclient.hpp" #include "lpxserver.hpp" -#include "drivertests.hpp" +#include "eng-tests.hpp" #include "source.hpp" #include @@ -43,7 +43,7 @@ const int INVALID_SOCKET = -1; struct termios orig_termios; -static std::string strerror_str(int err) { +static drv::string strerror_str(int err) { char errbuf[256]; return strerror_r(errno, errbuf, 256); } @@ -73,7 +73,7 @@ static void enable_tty_raw() { assert(status >= 0); } -static SOCKET open_connection(std::string_view target, std::string &err) { +static SOCKET open_connection(drv::string_view target, drv::string &err) { struct addrinfo *addrs = nullptr; struct addrinfo *goodaddr = nullptr; struct addrinfo hints; @@ -86,7 +86,7 @@ static SOCKET open_connection(std::string_view target, std::string &err) { hints.ai_flags = AI_NUMERICSERV; err.clear(); - std::string host, port; + drv::string host, port; drv::split_host_port(target, host, port); int status = getaddrinfo(host.c_str(), port.c_str(), &hints, &addrs); if (status != 0) { @@ -119,7 +119,7 @@ error_general: return INVALID_SOCKET; } -static SOCKET listen_on_port(int port, std::string &err) { +static SOCKET listen_on_port(int port, drv::string &err) { int status, enable; err.clear(); @@ -150,7 +150,7 @@ error_errno: return INVALID_SOCKET; } -static SOCKET accept_on_socket(SOCKET listen_socket, std::string &err) { +static SOCKET accept_on_socket(SOCKET listen_socket, drv::string &err) { err.clear(); SOCKET chsock = accept(listen_socket, nullptr, nullptr); if (chsock >= 0) { @@ -170,7 +170,7 @@ static SOCKET accept_on_socket(SOCKET listen_socket, std::string &err) { // zero: would block // negative: channel closed, possibly cleanly or possibly with error // -static int socket_send(SOCKET socket, const char *bytes, int nbytes, std::string &err) { +static int socket_send(SOCKET socket, const char *bytes, int nbytes, drv::string &err) { err.clear(); int wbytes = send(socket, bytes, nbytes, 0); if (wbytes < 0) { @@ -185,7 +185,7 @@ static int socket_send(SOCKET socket, const char *bytes, int nbytes, std::string } } -static int socket_recv(SOCKET socket, char *bytes, int nbytes, std::string &err) { +static int socket_recv(SOCKET socket, char *bytes, int nbytes, drv::string &err) { err.clear(); int nrecv = recv(socket, bytes, nbytes, 0); if (nrecv < 0) { @@ -206,7 +206,7 @@ static int socket_close(SOCKET socket) { return close(socket); } -static int socket_poll(struct pollfd *pollvec, int pollcount, int mstimeout, std::string &err) { +static int socket_poll(struct pollfd *pollvec, int pollcount, int mstimeout, drv::string &err) { // socket_poll is implicitly expected to also poll stdin, // if the OS allows that. Linux does, so we add stdin to the // poll vector. The poll vector is required to have at diff --git a/luprex/core/cpp/driver-mingw.cpp b/luprex/core/cpp/driver-mingw.cpp index d3afa4ab..de15c385 100644 --- a/luprex/core/cpp/driver-mingw.cpp +++ b/luprex/core/cpp/driver-mingw.cpp @@ -12,7 +12,7 @@ #include "textgame.hpp" #include "lpxclient.hpp" #include "lpxserver.hpp" -#include "drivertests.hpp" +#include "eng-tests.hpp" #include "source.hpp" #include @@ -35,8 +35,8 @@ #define CHBUF_SIZE (256*1024) #define POLLVEC_SIZE (DrivenEngine::MAX_CHAN+1) -static std::unique_ptr chbuf; -static std::unique_ptr pollvec; +static drv::unique_ptr chbuf; +static drv::unique_ptr pollvec; static void set_nonblocking(SOCKET sock) { u_long mode = 1; // 1 to enable non-blocking socket @@ -44,8 +44,8 @@ static void set_nonblocking(SOCKET sock) { assert(status == 0); } -static std::string winsock_error_string(int errcode) { - std::ostringstream oss; +static drv::string winsock_error_string(int errcode) { + drv::ostringstream oss; oss << "error " << errcode; return oss.str(); } @@ -55,15 +55,15 @@ static PADDRINFOA find_good_addr(PADDRINFOA addrinfo) { if (addr->ai_family == AF_INET) { return addr; } - }std::string + }drv::string return nullptr; } -static SOCKET open_connection(std::string_view target, std::string &err) { +static SOCKET open_connection(drv::string_view target, drv::string &err) { PADDRINFOA addrs = nullptr; PADDRINFOA goodaddr = nullptr; SOCKET sock = INVALID_SOCKET; - std::string_view host, port; + drv::string_view host, port; err.clear(); util::split_host_port(target, host, port); @@ -107,7 +107,7 @@ error: return SOCKET_ERROR; } -SOCKET listen_on_port(int port, std::string &err) { +SOCKET listen_on_port(int port, drv::string &err) { int status; err.clear(); SOCKET sock = socket(AF_INET, SOCK_STREAM, 0); @@ -140,7 +140,7 @@ error: return SOCKET_ERROR; } -static SOCKET accept_on_socket(SOCKET listen_socket, std::string &err) { +static SOCKET accept_on_socket(SOCKET listen_socket, drv::string &err) { SOCKET chsock = accept(listen_socket, nullptr, nullptr); if (chsock != INVALID_SOCKET) { set_nonblocking(chsock); @@ -156,7 +156,7 @@ static SOCKET accept_on_socket(SOCKET listen_socket, std::string &err) { } } -static int socket_send(SOCKET socket, const char *bytes, int nbytes, std::string &err) { +static int socket_send(SOCKET socket, const char *bytes, int nbytes, drv::string &err) { err.clear(); int wbytes = send(socket, bytes, nbytes, 0); if (wbytes == SOCKET_ERROR) { @@ -173,7 +173,7 @@ static int socket_send(SOCKET socket, const char *bytes, int nbytes, std::string } } -static int socket_recv(SOCKET socket, char *bytes, int nbytes, std::string &err) { +static int socket_recv(SOCKET socket, char *bytes, int nbytes, drv::string &err) { err.clear(); int nrecv = recv(socket, bytes, nbytes, 0); if (nrecv < 0) { @@ -195,7 +195,7 @@ static int socket_close(SOCKET socket) { return closesocket(socket); } -static int socket_poll(struct pollfd *pollvec, int pollcount, int mstimeout, std::string &err) { +static int socket_poll(struct pollfd *pollvec, int pollcount, int mstimeout, drv::string &err) { int status = WSAPoll(pollvec, pollcount, mstimeout); if (status < 0) { err = winsock_error_string(WSAGetLastError()); diff --git a/luprex/core/cpp/driver-util.cpp b/luprex/core/cpp/driver-util.cpp index a0d78b63..32d5501c 100644 --- a/luprex/core/cpp/driver-util.cpp +++ b/luprex/core/cpp/driver-util.cpp @@ -1,5 +1,6 @@ #include "wrap-string.hpp" +#include "wrap-string-view.hpp" #include "wrap-vector.hpp" #include "driver-util.hpp" @@ -8,9 +9,9 @@ namespace drv { -void split_host_port(std::string_view target, std::string &host, std::string &port) { +void split_host_port(drv::string_view target, drv::string &host, drv::string &port) { size_t lastcolon = target.rfind(':'); - if (lastcolon == std::string_view::npos) { + if (lastcolon == drv::string_view::npos) { host = ""; port = ""; return; } host = target.substr(0, lastcolon); @@ -20,11 +21,11 @@ void split_host_port(std::string_view target, std::string &host, std::string &po } } -std::vector parse_control_lst(std::string_view ctrl) { - std::vector result; +drv::vector parse_control_lst(drv::string_view ctrl) { + drv::vector result; while (!ctrl.empty()) { - std::string_view line = util::sv_read_line(ctrl); - std::string_view trimmed = util::sv_trim(line); + drv::string_view line = util::sv_read_line(ctrl); + drv::string_view trimmed = util::sv_trim(line); if ((trimmed.size() > 0) && (trimmed[0] != '#')) { result.emplace_back(trimmed); } @@ -37,7 +38,7 @@ std::vector parse_control_lst(std::string_view ctrl) { LuaDefine(unittests_driverutil, "", "some unit tests") { // Test split_host_port - std::string host, port; + drv::string host, port; drv::split_host_port("stanford.edu:80", host, port); LuaAssertStrEq(L, host, "stanford.edu"); LuaAssertStrEq(L, port, "80"); diff --git a/luprex/core/cpp/driver-util.hpp b/luprex/core/cpp/driver-util.hpp index 80cc239c..aeef97e7 100644 --- a/luprex/core/cpp/driver-util.hpp +++ b/luprex/core/cpp/driver-util.hpp @@ -3,14 +3,14 @@ #define DRIVER_UTIL_HPP #include "wrap-string.hpp" +#include "wrap-string-view.hpp" #include "wrap-vector.hpp" -#include "wrap-map.hpp" namespace drv { -void split_host_port(std::string_view target, std::string &host, std::string &port); +void split_host_port(drv::string_view target, drv::string &host, drv::string &port); -std::vector parse_control_lst(std::string_view ctrl); +drv::vector parse_control_lst(drv::string_view ctrl); } diff --git a/luprex/core/cpp/drivertests.cpp b/luprex/core/cpp/eng-tests.cpp similarity index 93% rename from luprex/core/cpp/drivertests.cpp rename to luprex/core/cpp/eng-tests.cpp index 670226fa..04e55e92 100644 --- a/luprex/core/cpp/drivertests.cpp +++ b/luprex/core/cpp/eng-tests.cpp @@ -1,6 +1,6 @@ #include "wrap-string.hpp" -#include "drivertests.hpp" +#include "eng-tests.hpp" #include "drivenengine.hpp" #include "streambuffer.hpp" #include "world.hpp" @@ -8,16 +8,16 @@ #include static void write_closed_message(Channel *ch, StreamBuffer *out) { - std::ostringstream oss; + eng::ostringstream oss; oss << "Chan " << ch->chid() << " closed [" << ch->error() << "]\n"; out->write_bytes(oss.str()); } static void dump_lines(StreamBuffer *in, StreamBuffer *out, int chid) { while (true) { - std::string l = in->readline(); + eng::string l = in->readline(); if (l == "") break; - std::ostringstream oss; + eng::ostringstream oss; oss << "Chan " << chid << ": " << l; out->write_bytes(oss.str()); } @@ -34,7 +34,7 @@ class DriverStubTest : public DrivenEngine { // the output from the server. class DriverWebServerTest : public DrivenEngine { public: - std::vector channels_; + eng::vector channels_; virtual void event_init(int argc, char *argv[]) { SharedChannel ch = new_outgoing_channel("stanford.edu:80"); ch->out()->write_bytes("GET http://stanford.edu/index.html HTTP/1.1\n\n"); @@ -44,7 +44,7 @@ public: virtual void event_update() { SharedChannel stdioch = get_stdio_channel(); dump_lines(stdioch->in(), stdioch->out(), 0); - std::vector keep; + eng::vector keep; for (SharedChannel &ch : channels_) { dump_lines(ch->in(), stdioch->out(), ch->chid()); if (ch->closed()) { @@ -60,7 +60,7 @@ public: // This test produces a DNS resolution failure. class DriverDNSFailTest : public DrivenEngine { public: - std::vector channels_; + eng::vector channels_; virtual void event_init(int argc, char *argv[]) { SharedChannel ch = new_outgoing_channel("akjsdkajshdakjshd.alk:80"); ch->out()->write_bytes("GET http://stanford.edu/index.html HTTP/1.1\n\n"); @@ -70,7 +70,7 @@ public: virtual void event_update() { SharedChannel stdioch = get_stdio_channel(); dump_lines(stdioch->in(), stdioch->out(), 0); - std::vector keep; + eng::vector keep; for (SharedChannel &ch : channels_) { dump_lines(ch->in(), stdioch->out(), ch->chid()); if (ch->closed()) { diff --git a/luprex/core/cpp/drivertests.hpp b/luprex/core/cpp/eng-tests.hpp similarity index 100% rename from luprex/core/cpp/drivertests.hpp rename to luprex/core/cpp/eng-tests.hpp diff --git a/luprex/core/cpp/gui.cpp b/luprex/core/cpp/gui.cpp index 35e99722..ee013f10 100644 --- a/luprex/core/cpp/gui.cpp +++ b/luprex/core/cpp/gui.cpp @@ -22,7 +22,7 @@ Gui *Gui::fetch_global_pointer(lua_State *L) { return result; } -void Gui::menu_item(const std::string &action, const std::string &label) { +void Gui::menu_item(const eng::string &action, const eng::string &label) { GuiElt elt; elt.type_ = GuiElt::TYPE_MENU_ITEM; elt.action_ = action; @@ -30,7 +30,7 @@ void Gui::menu_item(const std::string &action, const std::string &label) { elts_.push_back(elt); } -bool Gui::has_action(const std::string &action) const { +bool Gui::has_action(const eng::string &action) const { for (const GuiElt &elt : elts_) { if (elt.action_ == action) { return true; @@ -39,15 +39,15 @@ bool Gui::has_action(const std::string &action) const { return false; } -std::string Gui::get_action(int index) { +eng::string Gui::get_action(int index) { if ((index < 0) || (index >= int(elts_.size()))) { return ""; } return elts_[index].action(); } -std::string Gui::menu_debug_string() const { - std::ostringstream oss; +eng::string Gui::menu_debug_string() const { + eng::ostringstream oss; int index = 0; for (const GuiElt &elt : elts()) { oss << index << " " << elt.label() << std::endl; @@ -60,8 +60,8 @@ LuaDefine(gui_menu_item, "action,label", "add a menu item to the current gui") { Gui *gui = Gui::fetch_global_pointer(L); LuaArg laction, llabel; LuaStack LS(L, laction, llabel); - std::string action = LS.ckstring(laction); - std::string label = LS.ckstring(llabel); + eng::string action = LS.ckstring(laction); + eng::string label = LS.ckstring(llabel); if (!util::has_prefix(action, "cb_")) { luaL_error(L, "menuitem callbacks must start with cb_"); } diff --git a/luprex/core/cpp/gui.hpp b/luprex/core/cpp/gui.hpp index 5a42be8e..103e50b3 100644 --- a/luprex/core/cpp/gui.hpp +++ b/luprex/core/cpp/gui.hpp @@ -16,20 +16,20 @@ public: }; private: Type type_; - std::string action_; - std::string label_; + eng::string action_; + eng::string label_; GuiElt() {} public: ~GuiElt() {} Type type() const { return type_; } - const std::string &action() const { return action_; } - const std::string &label() const { return label_; } + const eng::string &action() const { return action_; } + const eng::string &label() const { return label_; } }; class Gui { public: - using EltVec = std::vector; + using EltVec = eng::vector; private: int64_t place_; EltVec elts_; @@ -38,10 +38,10 @@ public: int64_t place() { return place_; } const EltVec &elts() const { return elts_; } void clear(int64_t p) { place_ = p; elts_.clear(); } - bool has_action(const std::string &action) const; - void menu_item(const std::string &action, const std::string &label); - std::string get_action(int index); - std::string menu_debug_string() const; + bool has_action(const eng::string &action) const; + void menu_item(const eng::string &action, const eng::string &label); + eng::string get_action(int index); + eng::string menu_debug_string() const; // Put a pointer to a gui into the lua registry. // diff --git a/luprex/core/cpp/idalloc.cpp b/luprex/core/cpp/idalloc.cpp index 0c3f9221..f34f778f 100644 --- a/luprex/core/cpp/idalloc.cpp +++ b/luprex/core/cpp/idalloc.cpp @@ -1,13 +1,12 @@ #include "wrap-map.hpp" #include "wrap-sstream.hpp" -#include "wrap-ostream.hpp" #include "wrap-deque.hpp" +#include "wrap-ostream.hpp" #include "idalloc.hpp" - -static bool ranges_equal(const std::deque &dq, int64_t a, int64_t b, int64_t c) { +static bool ranges_equal(const eng::deque &dq, int64_t a, int64_t b, int64_t c) { if (dq.size() != 3) return false; if (dq[0] != a) return false; if (dq[1] != b) return false; @@ -82,8 +81,8 @@ void IdGlobalPool::deserialize(StreamBuffer *sb) { } } -std::string IdGlobalPool::debug_string() const { - std::ostringstream oss; +eng::string IdGlobalPool::debug_string() const { + eng::ostringstream oss; oss << "next_batch:" << util::hex64() << next_batch_ << " "; oss << "next_id:" << util::hex64() << next_id_ << " "; oss << "salvaged:"; @@ -196,7 +195,7 @@ void IdPlayerPool::diff(const IdPlayerPool &auth, StreamBuffer *sb) const { sb->write_uint8(auth.ranges_.size()); // Build up an index of the known IDs. - std::map index; + eng::map index; for (int i = 0; i < int(ranges_.size()); i++) { index[ranges_[i]] = i; } @@ -225,7 +224,7 @@ void IdPlayerPool::patch(StreamBuffer *sb, DebugCollector *dbc) { DebugLine(dbc) << "IdPlayerPool modified"; fifo_capacity_ = fifo_cap; int nranges = sb->read_uint8(); - std::deque old = std::move(ranges_); + eng::deque old = std::move(ranges_); ranges_.clear(); for (int i = 0; i < nranges; i++) { int index = sb->read_uint8(); @@ -238,8 +237,8 @@ void IdPlayerPool::patch(StreamBuffer *sb, DebugCollector *dbc) { } } -std::string IdPlayerPool::debug_string() const { - std::ostringstream oss; +eng::string IdPlayerPool::debug_string() const { + eng::ostringstream oss; oss << "cap:" << fifo_capacity_ << " ids:"; for (int i = 0; i < int(ranges_.size()); i++) { if (i > 0) oss << ","; diff --git a/luprex/core/cpp/idalloc.hpp b/luprex/core/cpp/idalloc.hpp index df226e04..cf5b425e 100644 --- a/luprex/core/cpp/idalloc.hpp +++ b/luprex/core/cpp/idalloc.hpp @@ -67,8 +67,8 @@ #include "wrap-map.hpp" #include "wrap-sstream.hpp" -#include "wrap-ostream.hpp" #include "wrap-deque.hpp" +#include "wrap-ostream.hpp" #include "luastack.hpp" #include "streambuffer.hpp" @@ -111,10 +111,10 @@ public: void deserialize(StreamBuffer *sb); // Generate a debug string. - std::string debug_string() const; + eng::string debug_string() const; private: - std::vector salvaged_; + eng::vector salvaged_; int64_t next_batch_; int64_t next_id_; friend int unittests_idalloc(lua_State *L); @@ -173,12 +173,12 @@ public: void patch(StreamBuffer *sb, DebugCollector *dbc); // Debug string. - std::string debug_string() const; + eng::string debug_string() const; private: IdGlobalPool *global_; int fifo_capacity_; - std::deque ranges_; + eng::deque ranges_; friend int lfn_unittests_idalloc(lua_State *L); }; diff --git a/luprex/core/cpp/invocation.cpp b/luprex/core/cpp/invocation.cpp index b25c7537..f2311152 100644 --- a/luprex/core/cpp/invocation.cpp +++ b/luprex/core/cpp/invocation.cpp @@ -6,8 +6,8 @@ #include "invocation.hpp" -const std::string &InvocationData::get(const std::string &key) const { - static std::string blank_; +const eng::string &InvocationData::get(const eng::string &key) const { + static eng::string blank_; auto iter = find(key); if (iter == end()) { return blank_; @@ -29,18 +29,18 @@ void InvocationData::deserialize(StreamBuffer *sb) { clear(); int size = sb->read_uint16(); for (int i = 0; i < size; i++) { - std::string key = sb->read_string(); - std::string val = sb->read_string(); + eng::string key = sb->read_string(); + eng::string val = sb->read_string(); (*this)[key] = val; } } Invocation::Invocation() : kind_(KIND_INVALID), actor_(0), place_(0) {} -Invocation::Invocation(Kind kind, int64_t actor, int64_t place, const std::string &action, const InvocationData &data) +Invocation::Invocation(Kind kind, int64_t actor, int64_t place, const eng::string &action, const InvocationData &data) : kind_(kind), actor_(actor), place_(place), action_(action), data_(data) {} -Invocation::Invocation(Kind kind, int64_t actor, int64_t place, const std::string &action) +Invocation::Invocation(Kind kind, int64_t actor, int64_t place, const eng::string &action) : kind_(kind), actor_(actor), place_(place), action_(action) {} void Invocation::serialize(StreamBuffer *sb) const { @@ -59,8 +59,8 @@ void Invocation::deserialize(StreamBuffer *sb) { data_.deserialize(sb); } -std::string Invocation::debug_string() { - std::ostringstream oss; +eng::string Invocation::debug_string() { + eng::ostringstream oss; oss << "inv["; switch (kind_) { case KIND_INVALID: oss << "invalid"; break; diff --git a/luprex/core/cpp/invocation.hpp b/luprex/core/cpp/invocation.hpp index 3bc2b4c2..648561fe 100644 --- a/luprex/core/cpp/invocation.hpp +++ b/luprex/core/cpp/invocation.hpp @@ -8,9 +8,9 @@ #include "streambuffer.hpp" -class InvocationData : public std::map { +class InvocationData : public eng::map { public: - const std::string &get(const std::string &key) const; + const eng::string &get(const eng::string &key) const; void serialize(StreamBuffer *sb) const; void deserialize(StreamBuffer *sb); @@ -31,27 +31,27 @@ private: Kind kind_; int64_t actor_; int64_t place_; - std::string action_; + eng::string action_; InvocationData data_; public: Invocation(); - Invocation(Kind kind, int64_t actor, int64_t place, const std::string &action, const InvocationData &data); - Invocation(Kind kind, int64_t actor, int64_t place, const std::string &action); + Invocation(Kind kind, int64_t actor, int64_t place, const eng::string &action, const InvocationData &data); + Invocation(Kind kind, int64_t actor, int64_t place, const eng::string &action); bool valid() const { return kind_ != KIND_INVALID; } Kind kind() const { return kind_; } int64_t actor() const { return actor_; } int64_t place() const { return place_; } - const std::string &action() const { return action_; } + const eng::string &action() const { return action_; } const InvocationData &data() const { return data_; } void serialize(StreamBuffer *sb) const; void deserialize(StreamBuffer *sb); - std::string debug_string(); + eng::string debug_string(); }; -class InvocationQueue : public std::deque { +class InvocationQueue : public eng::deque { }; diff --git a/luprex/core/cpp/lpxclient.cpp b/luprex/core/cpp/lpxclient.cpp index d6d4c132..377e8c38 100644 --- a/luprex/core/cpp/lpxclient.cpp +++ b/luprex/core/cpp/lpxclient.cpp @@ -100,7 +100,7 @@ public: void send_lua_source(const util::LuaSourceVec &sv) { StreamBuffer serial; SourceDB::serialize_source(sv, &serial); - std::string sstr = serial.read_entire_contents(); + eng::string sstr = serial.read_entire_contents(); Invocation inv(Invocation::KIND_LUA_SOURCE, actor_id_, actor_id_, sstr); send_invocation(inv); } @@ -131,7 +131,7 @@ public: } void do_choose_command(const StringVec &cmd) { - std::string action = gui_.get_action(util::strtoint(cmd[1], -1)); + eng::string action = gui_.get_action(util::strtoint(cmd[1], -1)); if (action == "") { stdostream() << "Invalid menu item #" << std::endl; return; @@ -252,7 +252,7 @@ public: // Check for keyboard input on stdin. while (true) { - std::string line = get_stdio_channel()->in()->readline(); + eng::string line = get_stdio_channel()->in()->readline(); if (line == "") break; console_.add(line); get_stdio_channel()->set_prompt(console_.get_prompt()); diff --git a/luprex/core/cpp/lpxserver.cpp b/luprex/core/cpp/lpxserver.cpp index de45fa13..46920297 100644 --- a/luprex/core/cpp/lpxserver.cpp +++ b/luprex/core/cpp/lpxserver.cpp @@ -15,8 +15,8 @@ public: SharedChannel channel_; UniqueWorld sync_; }; -using UniqueClient = std::unique_ptr; -using ClientVector = std::vector; +using UniqueClient = eng::unique_ptr; +using ClientVector = eng::vector; class LpxServer : public DrivenEngine { public: @@ -139,7 +139,7 @@ public: // Check for keyboard input on stdin. while (true) { - std::string line = get_stdio_channel()->in()->readline(); + eng::string line = get_stdio_channel()->in()->readline(); if (line == "") break; console_.add(line); get_stdio_channel()->set_prompt(console_.get_prompt()); diff --git a/luprex/core/cpp/luaconsole.cpp b/luprex/core/cpp/luaconsole.cpp index 7c31731f..fcab7dd0 100644 --- a/luprex/core/cpp/luaconsole.cpp +++ b/luprex/core/cpp/luaconsole.cpp @@ -16,9 +16,9 @@ LuaConsole::~LuaConsole() { lua_close(lua_state_); } -static LuaConsole::StringVec split_words(const std::string &raw) { +static LuaConsole::StringVec split_words(const eng::string &raw) { LuaConsole::StringVec result; - std::string acc; + eng::string acc; for (char c : raw) { if ((c == ' ')||(c == '\n')||(c == '\r')) { if (!acc.empty()) { @@ -41,7 +41,7 @@ LuaConsole::StringVec LuaConsole::get_command() { return result; } -void LuaConsole::synerr(const std::string &msg) { +void LuaConsole::synerr(const eng::string &msg) { words_.clear(); words_.push_back("syntax"); words_.push_back(msg); @@ -104,7 +104,7 @@ void LuaConsole::clear_raw_input() { prompt_ = "> "; } -void LuaConsole::add(std::string line) { +void LuaConsole::add(eng::string line) { for (int i = 0; i < int(line.size()); i++) { if (line[i] == '\n') line[i] = ' '; } @@ -122,17 +122,17 @@ void LuaConsole::add(std::string line) { } // Translate lua expression, deal with initial prefix. - std::string partial; - std::string lua_mode; + eng::string partial; + eng::string lua_mode; if (util::has_prefix(raw_input_, "?=")) { lua_mode = "luaprobe"; - partial = std::string("return ") + raw_input_.substr(2); + partial = eng::string("return ") + raw_input_.substr(2); } else if (util::has_prefix(raw_input_, "?")) { lua_mode = "luaprobe"; partial = raw_input_.substr(1); } else if (util::has_prefix(raw_input_, "=")) { lua_mode = "luainvoke"; - partial = std::string("return ") + raw_input_.substr(1); + partial = eng::string("return ") + raw_input_.substr(1); } else { lua_mode = "luainvoke"; partial = raw_input_; diff --git a/luprex/core/cpp/luaconsole.hpp b/luprex/core/cpp/luaconsole.hpp index cc050851..e26004bf 100644 --- a/luprex/core/cpp/luaconsole.hpp +++ b/luprex/core/cpp/luaconsole.hpp @@ -49,18 +49,18 @@ class LuaConsole { public: - using StringVec = std::vector; + using StringVec = eng::vector; private: lua_State *lua_state_; - std::string raw_input_; + eng::string raw_input_; int lines_; - std::string prompt_; + eng::string prompt_; StringVec words_; void clear_raw_input(); void simplify(const StringVec &words); - void synerr(const std::string &msg); + void synerr(const eng::string &msg); public: LuaConsole(); @@ -70,7 +70,7 @@ public: // // You should update the prompt immediately after 'add'. // - const std::string &get_prompt() { return prompt_; } + const eng::string &get_prompt() { return prompt_; } // Get the command words. // @@ -82,7 +82,7 @@ public: // Add a line of text that was just read from the console. // - void add(std::string line); + void add(eng::string line); }; diff --git a/luprex/core/cpp/luastack.cpp b/luprex/core/cpp/luastack.cpp index 2040f5e7..b19c5222 100644 --- a/luprex/core/cpp/luastack.cpp +++ b/luprex/core/cpp/luastack.cpp @@ -55,11 +55,11 @@ lua_Number LuaStack::cknumber(LuaSlot s) const { return lua_tonumber(L_, s); } -std::string LuaStack::ckstring(LuaSlot s) const { +eng::string LuaStack::ckstring(LuaSlot s) const { luaL_checktype(L_, s, LUA_TSTRING); size_t len; const char *str = lua_tolstring(L_, s, &len); - return std::string(str, len); + return eng::string(str, len); } lua_State *LuaStack::ckthread(LuaSlot s) const { @@ -154,7 +154,7 @@ lua_State *LuaStack::newthread(LuaSlot target) const { return result; } -bool LuaStack::validclassname(const std::string &cname) { +bool LuaStack::validclassname(const eng::string &cname) { if (cname.empty()) return false; if (cname == "_G") return false; return true; @@ -165,8 +165,8 @@ bool LuaStack::validclassname(LuaSlot slot) const { return validclassname(ckstring(slot)); } -std::string LuaStack::classname(LuaSlot tab) const { - std::string result; +eng::string LuaStack::classname(LuaSlot tab) const { + eng::string result; if (istable(tab)) { lua_pushstring(L_, "__class"); lua_rawget(L_, tab); @@ -177,7 +177,7 @@ std::string LuaStack::classname(LuaSlot tab) const { if (lua_rawequal(L_, -1, tab)) { size_t len; const char *s = lua_tolstring(L_, -3, &len); - result = std::string(s, len); + result = eng::string(s, len); if (!validclassname(result)) { result = ""; } @@ -190,7 +190,7 @@ std::string LuaStack::classname(LuaSlot tab) const { return result; } -std::string LuaStack::getclass(LuaSlot classtab, LuaSlot classname) const { +eng::string LuaStack::getclass(LuaSlot classtab, LuaSlot classname) const { lua_checkstack(L_, 20); LuaVar globtab, cname; LuaStack LS(L_, globtab, cname); @@ -198,19 +198,19 @@ std::string LuaStack::getclass(LuaSlot classtab, LuaSlot classname) const { if (LS.isstring(classname)) { if (!validclassname(LS.ckstring(classname))) { - std::string err = "invalid class name: " + LS.ckstring(classname); + eng::string err = "invalid class name: " + LS.ckstring(classname); LS.result(); return err; } LS.rawget(classtab, globtab, classname); if (!LS.istable(classtab)) { - std::string err = "not a class: " + LS.ckstring(classname); + eng::string err = "not a class: " + LS.ckstring(classname); LS.result(); return err; } LS.rawget(cname, classtab, "__class"); if (!LS.rawequal(cname, classname)) { - std::string err = "not a valid class: " + LS.ckstring(classname); + eng::string err = "not a valid class: " + LS.ckstring(classname); LS.result(); return err; } @@ -219,42 +219,42 @@ std::string LuaStack::getclass(LuaSlot classtab, LuaSlot classname) const { } else if (LS.istable(classname)) { LS.rawget(cname, classname, "__class"); if (!LS.isstring(cname)) { - std::string err = "table is not a class."; + eng::string err = "table is not a class."; LS.result(); return err; } if (!validclassname(LS.ckstring(cname))) { - std::string err = "invalid class name: " + LS.ckstring(cname); + eng::string err = "invalid class name: " + LS.ckstring(cname); LS.result(); return err; } LS.rawget(classtab, globtab, cname); if (!LS.rawequal(classtab, classname)) { - std::string err = "not a valid class: " + LS.ckstring(cname); + eng::string err = "not a valid class: " + LS.ckstring(cname); LS.result(); return err; } LS.result(); return ""; } else { - std::string err = "getclass expects a string or a classtab"; + eng::string err = "getclass expects a string or a classtab"; LS.result(); return err; } } -std::string LuaStack::getclass(LuaSlot tab, const char *name) const { +eng::string LuaStack::getclass(LuaSlot tab, const char *name) const { push_any_value(name); LuaSpecial classname(lua_gettop(L_)); - std::string err = getclass(tab, classname); + eng::string err = getclass(tab, classname); lua_pop(L_, 1); return err; } -std::string LuaStack::getclass(LuaSlot tab, const std::string &name) const { +eng::string LuaStack::getclass(LuaSlot tab, const eng::string &name) const { push_any_value(name); LuaSpecial classname(lua_gettop(L_)); - std::string err = getclass(tab, classname); + eng::string err = getclass(tab, classname); lua_pop(L_, 1); return err; } @@ -295,7 +295,7 @@ void LuaStack::makeclass(LuaSlot tab, const char *name) const { lua_pop(L_, 1); } -void LuaStack::makeclass(LuaSlot tab, const std::string &name) const { +void LuaStack::makeclass(LuaSlot tab, const eng::string &name) const { push_any_value(name); LuaSpecial classname(lua_gettop(L_)); makeclass(tab, classname); diff --git a/luprex/core/cpp/luastack.hpp b/luprex/core/cpp/luastack.hpp index 0204dc30..38d5dd48 100644 --- a/luprex/core/cpp/luastack.hpp +++ b/luprex/core/cpp/luastack.hpp @@ -65,12 +65,12 @@ // LS.rawget(value, tab, key); // // Nominally, you would expect value, tab, and key to be lua local -// variables. But if you pass a std::string for key, then LuaStack will +// variables. But if you pass a eng::string for key, then LuaStack will // automatically convert it. In general, class LuaStack can -// convert lua_Integer, lua_Number, std::string, bool, and LuaNil. +// convert lua_Integer, lua_Number, eng::string, bool, and LuaNil. // // On output, LuaStack can convert lua_Integers, lua_Numbers, and -// std::strings. In this case, strict type checking is done. If +// eng::strings. In this case, strict type checking is done. If // there is a type mismatch, a lua error is thrown. // // You can use the operator 'set' to assign a value to a lua local @@ -114,7 +114,7 @@ // // lua_Integer LuaStack::ckinteger(LuaSlot s) // lua_Number LuaStack::cknumber(LuaSlot s) -// std::string LuaStack::ckstring(LuaSlot s) +// eng::string LuaStack::ckstring(LuaSlot s) // lua_State *LuaStack::ckthread(LuaSlot s) // // Like the other operations, they are strict. @@ -295,7 +295,7 @@ private: void push_any_value(LuaNewTableMarker s) const { lua_newtable(L_); } void push_any_value(LuaNilMarker s) const { lua_pushnil(L_); } void push_any_value(LuaSlot s) const { lua_pushvalue(L_, s); } - void push_any_value(const std::string &s) const { lua_pushlstring(L_, s.c_str(), s.size()); } + void push_any_value(const eng::string &s) const { lua_pushlstring(L_, s.c_str(), s.size()); } void push_any_value(const char *s) const { lua_pushstring(L_, s); } void push_any_value(float s) const { lua_pushnumber(L_, s); } void push_any_value(double s) const { lua_pushnumber(L_, s); } @@ -360,7 +360,7 @@ public: lua_Integer ckinteger(LuaSlot s) const; int ckint(LuaSlot s) const; lua_Number cknumber(LuaSlot s) const; - std::string ckstring(LuaSlot s) const; + eng::string ckstring(LuaSlot s) const; lua_State *ckthread(LuaSlot s) const; void clearmetatable(LuaSlot tab) const; @@ -379,28 +379,28 @@ public: // Return true if the classname is legal. bool validclassname(LuaSlot value) const; - static bool validclassname(const std::string &cname); + static bool validclassname(const eng::string &cname); // Return the class name if x is a valid classtab. // Otherwise, returns empty string. If nonempty, the // result is guaranteed to be a validclassname. // This can also function as an "isclass" operator. - std::string classname(LuaSlot x) const; + eng::string classname(LuaSlot x) const; // Look up a class. // If there is a problem, returns an error message. // There are lots of error conditions, including such things // as no such class, corrupted class, classname invalid, etc. - std::string getclass(LuaSlot tab, LuaSlot name) const; - std::string getclass(LuaSlot tab, const char *name) const; - std::string getclass(LuaSlot tab, const std::string &name) const; + eng::string getclass(LuaSlot tab, LuaSlot name) const; + eng::string getclass(LuaSlot tab, const char *name) const; + eng::string getclass(LuaSlot tab, const eng::string &name) const; // Create a class, or look up an existing class. // WARNING: this routine assert-fails if the parameter is not // a valid classname. Check the classname before calling this! void makeclass(LuaSlot tab, LuaSlot name) const; void makeclass(LuaSlot tab, const char *name) const; - void makeclass(LuaSlot tab, const std::string &name) const; + void makeclass(LuaSlot tab, const eng::string &name) const; // Get the ID of a tangible. It's a little weird to put this in // this module. @@ -481,7 +481,7 @@ private: static LuaFunctionReg *LuaFunctionRegistry; public: - using List = std::vector; + using List = eng::vector; LuaFunctionReg(const char *name, const char *args, const char *docs, lua_CFunction f); static List all(); @@ -507,5 +507,5 @@ public: #define LuaStringify(x) #x #define LuaAssert(L, x) if (!(x)) { luaL_error((L), "Assert failed: %s (file %s line %d)", LuaStringify(x), __FILE__, __LINE__); } -#define LuaAssertStrEq(L, x, y) { std::string _s1_(x); std::string _s2_(y); if (_s1_ != _s2_) luaL_error((L), "Assert failed: value=%s (file %s line %d)", _s1_.c_str(), __FILE__, __LINE__); } +#define LuaAssertStrEq(L, x, y) { eng::string _s1_(x); eng::string _s2_(y); if (_s1_ != _s2_) luaL_error((L), "Assert failed: value=%s (file %s line %d)", _s1_.c_str(), __FILE__, __LINE__); } #endif // LUASTACK_HPP diff --git a/luprex/core/cpp/planemap.cpp b/luprex/core/cpp/planemap.cpp index f2d7e99a..8cb45a91 100644 --- a/luprex/core/cpp/planemap.cpp +++ b/luprex/core/cpp/planemap.cpp @@ -6,6 +6,7 @@ #include + // Cell X, Y coordinates are packed such that they have 24 bits for X and Y. // A cell is 10 Meters square. // Cell ID zero is used to represent an invalid position. @@ -61,7 +62,7 @@ static int64_t point_cell_id(float x, float y) { return cell_id(int64_t(cellx), int64_t(celly)); } -void PlaneMap::remove(const std::string &plane, int64_t cellid, PlaneItem *client) { +void PlaneMap::remove(const eng::string &plane, int64_t cellid, PlaneItem *client) { auto piter = planes_.find(plane); if (piter == planes_.end()) { return; @@ -81,13 +82,13 @@ void PlaneMap::remove(const std::string &plane, int64_t cellid, PlaneItem *clien } } -void PlaneMap::insert(const std::string &plane, int64_t cellid, PlaneItem *client) { +void PlaneMap::insert(const eng::string &plane, int64_t cellid, PlaneItem *client) { Plane &p = planes_[plane]; EltVec &l = p[cellid]; l.push_back(client); } -void PlaneItem::set_pos(const std::string &plane, float x, float y, float z) { +void PlaneItem::set_pos(const eng::string &plane, float x, float y, float z) { int64_t old_cell = point_cell_id(x_, y_); int64_t new_cell = point_cell_id(x, y); @@ -141,7 +142,7 @@ PlaneMap::~PlaneMap() { } } -PlaneMap::EltVec PlaneMap::get_cell(const std::string &plane, int64_t cellid) const { +PlaneMap::EltVec PlaneMap::get_cell(const eng::string &plane, int64_t cellid) const { PlaneMap::EltVec result; auto piter = planes_.find(plane); if (piter != planes_.end()) { @@ -162,7 +163,7 @@ int PlaneMap::total_cells() const { return total; } -PlaneMap::IdVector PlaneMap::scan_radius_unsorted(const std::string &plane, float x, float y, float radius, bool exclude_nowhere, int64_t special, bool omit) const { +PlaneMap::IdVector PlaneMap::scan_radius_unsorted(const eng::string &plane, float x, float y, float radius, bool exclude_nowhere, int64_t special, bool omit) const { PlaneMap::IdVector result; if ((special != 0)&&(!omit)) { result.push_back(special); @@ -193,7 +194,7 @@ PlaneMap::IdVector PlaneMap::scan_radius_unsorted(const std::string &plane, floa return result; } -PlaneMap::IdVector PlaneMap::scan_radius(const std::string &plane, float x, float y, float radius, bool exclude_nowhere, int64_t special, bool omit) const { +PlaneMap::IdVector PlaneMap::scan_radius(const eng::string &plane, float x, float y, float radius, bool exclude_nowhere, int64_t special, bool omit) const { PlaneMap::IdVector result = scan_radius_unsorted(plane, x, y, radius, exclude_nowhere, special, omit); if ((special != 0)&&(!omit)) { std::sort(result.begin() + 1, result.end()); diff --git a/luprex/core/cpp/planemap.hpp b/luprex/core/cpp/planemap.hpp index 99565fd5..1573e006 100644 --- a/luprex/core/cpp/planemap.hpp +++ b/luprex/core/cpp/planemap.hpp @@ -88,7 +88,7 @@ class PlaneItem { private: PlaneMap *pmap_; - std::string plane_; + eng::string plane_; float x_, y_, z_; int64_t id_; @@ -100,7 +100,7 @@ public: void set_id(int64_t id) { id_ = id; } int64_t id() const { return id_; } - const std::string &plane() const { return plane_; } + const eng::string &plane() const { return plane_; } const float x() const { return x_; } const float y() const { return y_; } const float z() const { return z_; } @@ -108,18 +108,18 @@ public: void untrack(); void track(PlaneMap *pmap); - void set_pos(const std::string &plane, float x, float y, float z); + void set_pos(const eng::string &plane, float x, float y, float z); void set_xyz(float x, float y, float z) { set_pos(plane_, x, y, z); } }; class PlaneMap { friend class PlaneItem; private: - using EltVec = std::vector; - using Plane = std::map; - std::map planes_; - void remove(const std::string &plane, int64_t cell, PlaneItem *client); - void insert(const std::string &plane, int64_t cell, PlaneItem *client); + using EltVec = eng::vector; + using Plane = eng::map; + eng::map planes_; + void remove(const eng::string &plane, int64_t cell, PlaneItem *client); + void insert(const eng::string &plane, int64_t cell, PlaneItem *client); public: using IdVector = util::IdVector; @@ -133,13 +133,13 @@ public: // omit - if true, remove the special ID from the list. // if false, prepend the special ID to the head of the list. // - IdVector scan_radius(const std::string &plane, float x, float y, float radius, bool exclude_nowhere, int64_t special, bool omit) const; - IdVector scan_radius_unsorted(const std::string &plane, float x, float y, float radius, bool exclude_nowhere, int64_t special, bool omit) const; + IdVector scan_radius(const eng::string &plane, float x, float y, float radius, bool exclude_nowhere, int64_t special, bool omit) const; + IdVector scan_radius_unsorted(const eng::string &plane, float x, float y, float radius, bool exclude_nowhere, int64_t special, bool omit) const; private: // unit testing stuff. friend int lfn_unittests_planemap(lua_State *L); - EltVec get_cell(const std::string &plane, int64_t cell) const; + EltVec get_cell(const eng::string &plane, int64_t cell) const; int total_cells() const; void clear() { planes_.clear(); } }; diff --git a/luprex/core/cpp/pprint.cpp b/luprex/core/cpp/pprint.cpp index b8549053..33997f8d 100644 --- a/luprex/core/cpp/pprint.cpp +++ b/luprex/core/cpp/pprint.cpp @@ -1,3 +1,4 @@ + #include "wrap-ostream.hpp" #include "pprint.hpp" @@ -7,7 +8,7 @@ #include -void atomic_print(LuaStack &LS, LuaSlot val, bool quote, std::ostream *os) { +void atomic_print(LuaStack &LS, LuaSlot val, bool quote, eng::ostream *os) { int tt = LS.type(val); switch (tt) { case LUA_TNIL: @@ -102,7 +103,7 @@ struct Inspector { bool indent; int maxlen; bool anyindent; - std::ostream *stream; + eng::ostream *stream; }; static void tabify(Inspector &insp, int level) { @@ -142,7 +143,7 @@ static void pprint_r(Inspector &insp, int level, LuaSlot root) { // Print the table's name, if any. bool is_class = false; bool is_tangible = false; - std::string cname = LS.classname(root); + eng::string cname = LS.classname(root); if (cname != "") { is_class = true; (*insp.stream) << ""; @@ -234,7 +235,7 @@ static void pprint_r(Inspector &insp, int level, LuaSlot root) { LS.result(); } -void pprint(LuaStack &LS0, LuaSlot root, bool indent, std::ostream *os) { +void pprint(LuaStack &LS0, LuaSlot root, bool indent, eng::ostream *os) { Inspector insp; LuaStack LS(LS0.state(), insp.ids); findtables(LS, root, insp.ids); @@ -252,7 +253,7 @@ LuaDefine(string_isidentifier, "str", "return true if the string is a valid lua LuaRet result; LuaStack LS(L, str, result); if (LS.isstring(str)) { - std::string s = LS.ckstring(str); + eng::string s = LS.ckstring(str); LS.set(result, util::is_identifier(s)); } else { LS.set(result, false); @@ -264,7 +265,7 @@ LuaDefine(string_print, "obj", "print the specified object into a string") { LuaArg val; LuaRet result; LuaStack LS(L, val, result); - std::ostringstream oss; + eng::ostringstream oss; atomic_print(LS, val, false, &oss); LS.set(result, oss.str()); return LS.result(); @@ -275,7 +276,7 @@ LuaDefine(string_pprint, "obj,indent", "pretty-print the specified object into a LuaRet result; LuaStack LS(L, root, indent, result); bool ind = LS.ckboolean(indent); - std::ostringstream oss; + eng::ostringstream oss; pprint(LS, root, ind, &oss); LS.set(result, oss.str()); return LS.result(); @@ -285,7 +286,7 @@ LuaDefine(tostring, "obj", "print the specified object into a string") { LuaArg val; LuaRet result; LuaStack LS(L, val, result); - std::ostringstream oss; + eng::ostringstream oss; atomic_print(LS, val, false, &oss); LS.set(result, oss.str()); return LS.result(); diff --git a/luprex/core/cpp/pprint.hpp b/luprex/core/cpp/pprint.hpp index 0e2980a9..2b689d13 100644 --- a/luprex/core/cpp/pprint.hpp +++ b/luprex/core/cpp/pprint.hpp @@ -23,16 +23,17 @@ #include "luastack.hpp" + // Atomic print to a stream. // // This prints an atomic value to a stream. If you give it a table, // it just prints "". This routine is the heart of the lua // primitives 'print' and 'tostring'. // -void atomic_print(LuaStack &LS, LuaSlot val, bool quote, std::ostream *os); +void atomic_print(LuaStack &LS, LuaSlot val, bool quote, eng::ostream *os); // Pretty print to a stream. // -void pprint(LuaStack &LS, LuaSlot val, bool indent, std::ostream *os); +void pprint(LuaStack &LS, LuaSlot val, bool indent, eng::ostream *os); #endif // PPRINT_HPP \ No newline at end of file diff --git a/luprex/core/cpp/printbuffer.cpp b/luprex/core/cpp/printbuffer.cpp index 3a547b73..90152483 100644 --- a/luprex/core/cpp/printbuffer.cpp +++ b/luprex/core/cpp/printbuffer.cpp @@ -3,9 +3,11 @@ #include "printbuffer.hpp" +#include + struct PrintBufferCore { // The most recent lines printed. - std::deque lines_; + eng::deque lines_; // Line number of the first line in the buffer. From this, all other // line numbers can be inferred. @@ -45,12 +47,12 @@ bool PrintBuffer::never_printed() const { return (core_->first_line_==0) && (core_->first_unchecked_==0) && (core_->lines_.size()==0); } -const std::string &PrintBuffer::nth(int n) const { +const eng::string &PrintBuffer::nth(int n) const { return core_->lines_[n - core_->first_line_]; } -std::string PrintBuffer::debug_string() const { - std::ostringstream oss; +eng::string PrintBuffer::debug_string() const { + eng::ostringstream oss; oss << core_->first_line_ << "," << core_->first_unchecked_ << ":"; for (int i = 0; i < int(core_->lines_.size()); i++) { oss << core_->lines_[i] << ";"; @@ -80,7 +82,7 @@ static void add_line(PrintBufferCore *core, const char *text, int len, bool auth } } -void PrintBuffer::add_string(const std::string &s, bool auth) { +void PrintBuffer::add_string(const eng::string &s, bool auth) { const char *text = s.c_str(); int len = s.size(); if (core_ == &shared_core) core_ = new PrintBufferCore; @@ -118,7 +120,7 @@ void PrintBuffer::serialize(StreamBuffer *sb) const { sb->write_uint32(core_->first_line_); sb->write_uint32(core_->first_unchecked_); sb->write_uint32(core_->lines_.size()); - for (const std::string &s : core_->lines_) { + for (const eng::string &s : core_->lines_) { sb->write_string(s); } } @@ -150,7 +152,7 @@ void PrintBuffer::diff(const PrintBuffer &auth, StreamBuffer *sb) const { sb->write_int32(auth.first_line()); sb->write_int32(auth.last_line()); for (int i = core_->first_unchecked_; i < auth.last_line(); i++) { - std::string line; + eng::string line; if (i >= auth.first_line()) line = auth.nth(i); sb->write_string(line); } @@ -174,7 +176,7 @@ void PrintBuffer::patch(StreamBuffer *sb, DebugCollector *dbc) { } } -bool PrintChanneler::channel(const PrintBuffer *printbuffer, std::ostream &ostream) { +bool PrintChanneler::channel(const PrintBuffer *printbuffer, eng::ostream &ostream) { if (printbuffer == nullptr) return false; if (printbuffer->first_line() > line_) { line_ = printbuffer->first_line(); @@ -187,7 +189,9 @@ bool PrintChanneler::channel(const PrintBuffer *printbuffer, std::ostream &ostre } Invocation PrintChanneler::invocation(int64_t actor_id) { - return Invocation(Invocation::KIND_FLUSH_PRINTS, actor_id, actor_id, std::to_string(line_), InvocationData()); + char buf[80]; + sprintf(buf, "%ld", line_); + return Invocation(Invocation::KIND_FLUSH_PRINTS, actor_id, actor_id, buf, InvocationData()); } LuaDefine(unittests_printbuffer, "", "some unit tests") { diff --git a/luprex/core/cpp/printbuffer.hpp b/luprex/core/cpp/printbuffer.hpp index 02488e1f..e06d2248 100644 --- a/luprex/core/cpp/printbuffer.hpp +++ b/luprex/core/cpp/printbuffer.hpp @@ -87,6 +87,7 @@ #include "invocation.hpp" #include "debugcollector.hpp" + struct PrintBufferCore; class PrintBuffer { @@ -112,10 +113,10 @@ public: bool never_printed() const; // Get the specified line number. - const std::string &nth(int n) const; + const eng::string &nth(int n) const; // Print the entire contents of the buffer to a string (for unit testing). - std::string debug_string() const; + eng::string debug_string() const; // Clear the buffer void clear(); @@ -123,7 +124,7 @@ public: // Add a string. If the string doesn't end in a newline, a newline // is added. The string is broken into lines, and the lines are added // to the PrintBuffer. - void add_string(const std::string &s, bool auth); + void add_string(const eng::string &s, bool auth); // Discard lines up to but not including line N. void discard_upto(int n); @@ -150,7 +151,7 @@ public: // Copy any new lines from the printbuffer to the stdostream. // Update the current line number. Return true if the printbuffer // contains any lines that have already been channeled. - bool channel(const PrintBuffer *pb, std::ostream &ostream); + bool channel(const PrintBuffer *pb, eng::ostream &ostream); // Generate an invocation that removes unnecessary lines from the // printbuffer. diff --git a/luprex/core/cpp/sched.cpp b/luprex/core/cpp/sched.cpp index 655b83ad..c06e845a 100644 --- a/luprex/core/cpp/sched.cpp +++ b/luprex/core/cpp/sched.cpp @@ -16,8 +16,8 @@ bool SchedEntry::operator < (const SchedEntry &other) const { return false; } -std::string SchedEntry::debug_string() const { - std::ostringstream oss; +eng::string SchedEntry::debug_string() const { + eng::ostringstream oss; oss << "(" << clock_ << "," << thread_id_ << "," << place_id_ << ")"; return oss.str(); } @@ -37,8 +37,8 @@ SchedEntry Schedule::pop() { return result; } -std::string Schedule::debug_string() { - std::ostringstream oss; +eng::string Schedule::debug_string() { + eng::ostringstream oss; for (const SchedEntry &se : schedule_) { oss << se.debug_string(); } diff --git a/luprex/core/cpp/sched.hpp b/luprex/core/cpp/sched.hpp index 4f0bb934..f11aa8a3 100644 --- a/luprex/core/cpp/sched.hpp +++ b/luprex/core/cpp/sched.hpp @@ -27,18 +27,18 @@ public: bool operator < (const SchedEntry &other) const; - std::string debug_string() const; + eng::string debug_string() const; }; class Schedule { private: - std::set schedule_; + eng::set schedule_; public: void add(int64_t clk, int64_t thid, int64_t plid); bool ready(int64_t clk) const; bool empty() const { return schedule_.empty(); } SchedEntry pop(); - std::string debug_string(); + eng::string debug_string(); void serialize(StreamBuffer *sb); void deserialize(StreamBuffer *sb); diff --git a/luprex/core/cpp/source.cpp b/luprex/core/cpp/source.cpp index 73071c0a..bf6d0347 100644 --- a/luprex/core/cpp/source.cpp +++ b/luprex/core/cpp/source.cpp @@ -34,7 +34,7 @@ LuaDefine(getclass, "classname", "get the classtab with the specified name") { LuaArg classname; LuaRet classtab; LuaStack LS(L, classname, classtab); - std::string err = LS.getclass(classtab, classname); + eng::string err = LS.getclass(classtab, classname); if (err != "") { luaL_error(L, "%s", err.c_str()); } @@ -45,7 +45,7 @@ LuaDefine(classname, "classtable", "get the class name from a class table") { LuaArg table; LuaRet result; LuaStack LS(L, table, result); - std::string rstr = LS.classname(table); + eng::string rstr = LS.classname(table); if (rstr == "") { LS.set(result, LuaNil); } else { @@ -54,10 +54,10 @@ LuaDefine(classname, "classtable", "get the class name from a class table") { return LS.result(); } -static void get_reg_name(const LuaFunctionReg *reg, std::string &classname, std::string &funcname) { - std::string name = reg->get_name(); +static void get_reg_name(const LuaFunctionReg *reg, eng::string &classname, eng::string &funcname) { + eng::string name = reg->get_name(); size_t upos = name.find('_'); - if (upos == std::string::npos) { + if (upos == eng::string::npos) { funcname = name; classname = ""; } else { @@ -86,7 +86,7 @@ static void load_builtin_class(lua_State *L, const char *name, lua_CFunction fun LS.result(); } -static void erase_builtin(LuaStack &LS, LuaSlot globtab, const std::string &classname, const std::string &funcname) { +static void erase_builtin(LuaStack &LS, LuaSlot globtab, const eng::string &classname, const eng::string &funcname) { if (classname.empty()) { LS.rawset(globtab, funcname, LuaNil); } else { @@ -130,7 +130,7 @@ static void source_install_builtins(lua_State *L) { LS.result(); } -static void get_info_table(LuaStack &LS, LuaSlot db, LuaSlot info, const std::string &fn) { +static void get_info_table(LuaStack &LS, LuaSlot db, LuaSlot info, const eng::string &fn) { LS.rawget(info, db, fn); if (!LS.istable(info)) { LS.set(info, LuaNewTable); @@ -139,13 +139,13 @@ static void get_info_table(LuaStack &LS, LuaSlot db, LuaSlot info, const std::st LS.rawset(info, "name", fn); } -static void calculate_loadresult(LuaStack &LS0, LuaSlot info, const std::string &fn, const std::string &code) { +static void calculate_loadresult(LuaStack &LS0, LuaSlot info, const eng::string &fn, const eng::string &code) { LuaVar loadresult; LuaStack LS(LS0.state(), loadresult); if (code == "") { LS.rawset(info, "loadresult", "missing or empty source file"); } else { - std::string chunk = "=" + fn; + eng::string chunk = "=" + fn; luaL_loadbuffer(LS.state(), code.c_str(), code.size(), chunk.c_str()); lua_replace(LS.state(), loadresult.index()); LS.rawset(info, "loadresult", loadresult); @@ -167,7 +167,7 @@ void SourceDB::diff(const SourceDB &auth, StreamBuffer *sb) { // Loop over the master database. MLS.set(mfn, LuaNil); while (MLS.next(mdb, mfn, minfo) != 0) { - std::string fn = MLS.ckstring(mfn); + eng::string fn = MLS.ckstring(mfn); assert(MLS.istable(minfo)); MLS.rawget(mseq, minfo, "sequence"); MLS.rawget(mhash, minfo, "hash"); @@ -196,7 +196,7 @@ void SourceDB::diff(const SourceDB &auth, StreamBuffer *sb) { // Loop over synch database. SLS.set(sfn, LuaNil); while (SLS.next(sdb, sfn, sinfo) != 0) { - std::string fn = SLS.ckstring(sfn); + eng::string fn = SLS.ckstring(sfn); assert(SLS.istable(sinfo)); MLS.set(mfn, fn); MLS.rawget(minfo, mdb, mfn); @@ -219,9 +219,9 @@ bool SourceDB::patch(StreamBuffer *sb, DebugCollector *dbc) { LS.rawget(db, LuaRegistry, "sourcedb"); int nupdates = sb->read_int32(); for (int i = 0; i < nupdates; i++) { - std::string fn = sb->read_string(); + eng::string fn = sb->read_string(); int sequence = sb->read_int32(); - std::string code = sb->read_string(); + eng::string code = sb->read_string(); DebugLine(dbc) << "Source file " << fn << " updated"; if (sequence < 0) { LS.rawset(db, fn, LuaNil); @@ -239,7 +239,7 @@ bool SourceDB::patch(StreamBuffer *sb, DebugCollector *dbc) { return (nupdates > 0); } -void SourceDB::set(const std::string &fn, const std::string &code, int sequence) { +void SourceDB::set(const eng::string &fn, const eng::string &code, int sequence) { lua_State *L = lua_state_; LuaVar db, info; LuaStack LS(L, db, info); @@ -253,7 +253,7 @@ void SourceDB::set(const std::string &fn, const std::string &code, int sequence) LS.result(); } -std::string SourceDB::get(const std::string &fn) { +eng::string SourceDB::get(const eng::string &fn) { lua_State *L = lua_state_; LuaVar db, info, code, sequence, loadresult; LuaStack LS(L, db, info, code, sequence, loadresult); @@ -266,15 +266,15 @@ std::string SourceDB::get(const std::string &fn) { LS.rawget(code, info, "code"); LS.rawget(sequence, info, "sequence"); LS.rawget(loadresult, info, "loadresult"); - std::string ccode = LS.ckstring(code); + eng::string ccode = LS.ckstring(code); int seqno = LS.ckint(sequence); - std::string cloadresult; + eng::string cloadresult; if (LS.isfunction(loadresult)) { cloadresult = ""; } else { cloadresult = LS.ckstring(loadresult); } - std::ostringstream oss; + eng::ostringstream oss; oss << seqno << ":" << ccode << ":" << cloadresult; LS.result(); return oss.str(); @@ -294,8 +294,8 @@ void SourceDB::update(const util::LuaSourceVec &source) { LS.cleartable(sourcedb, true); for (int i = 0; i < int(source.size()); i++) { - const std::string &file = source[i].first; - const std::string &code = source[i].second; + const eng::string &file = source[i].first; + const eng::string &code = source[i].second; std::cerr << "Compiling " << file << std::endl; LS.newtable(info); LS.rawset(info, "name", file); @@ -340,8 +340,8 @@ static void source_load_cfunctions(lua_State *L) { auto regs = LuaFunctionReg::all(); for (const LuaFunctionReg *r : regs) { lua_CFunction func = r->get_func(); - std::string classname; - std::string funcname; + eng::string classname; + eng::string funcname; get_reg_name(r, classname, funcname); if (classname.empty()) { LS.getglobaltable(classobj); @@ -356,7 +356,7 @@ static void source_load_cfunctions(lua_State *L) { // Run all the closures from the source database. // -static std::string source_load_lfunctions(lua_State *L) { +static eng::string source_load_lfunctions(lua_State *L) { LuaVar sourcedb, key, info, seq, closure, err; LuaStack LS(L, sourcedb, key, info, seq, closure, err); @@ -368,7 +368,7 @@ static std::string source_load_lfunctions(lua_State *L) { } // Sort the keys by sequence number. - std::map indices; + eng::map indices; LS.set(key, LuaNil); while (LS.next(sourcedb, key, info) != 0) { LS.rawget(seq, info, "sequence"); @@ -376,7 +376,7 @@ static std::string source_load_lfunctions(lua_State *L) { } // Now call the closures in the proper order. - std::ostringstream errss; + eng::ostringstream errss; for (const auto &p : indices) { LS.rawget(info, sourcedb, p.second); LS.rawget(closure, info, "loadresult"); @@ -399,12 +399,12 @@ static std::string source_load_lfunctions(lua_State *L) { } -std::string SourceDB::rebuild() { +eng::string SourceDB::rebuild() { lua_State *L = lua_state_; source_clear_globals(L); // source_install_builtins(L); source_load_cfunctions(L); - std::string errs = source_load_lfunctions(L); + eng::string errs = source_load_lfunctions(L); return errs; } @@ -417,7 +417,7 @@ void SourceDB::run_unittests() { LS.rawget(unittests, globtab, "unittests"); // Sort the unit test names. - std::set names; + eng::set names; LS.set(name, LuaNil); while (LS.next(unittests, name, func) != 0) { if (LS.isfunction(func) && LS.isstring(name)) { @@ -427,7 +427,7 @@ void SourceDB::run_unittests() { // Run the functions in order bool any = false; - for (const std::string &name : names) { + for (const eng::string &name : names) { std::cerr << "Running unittests." << name << std::endl; LS.rawget(func, unittests, name); @@ -464,7 +464,7 @@ void SourceDB::init(lua_State *L) { LS.set(funcname, LuaNil); while (LS.next(classtab, funcname, funcp) != 0) { if (LS.isstring(funcname) && LS.iscfunction(funcp)) { - std::string full = "cfunc:"; + eng::string full = "cfunc:"; full += LS.ckstring(classname); full += "."; full += LS.ckstring(funcname); @@ -491,8 +491,8 @@ void SourceDB::deserialize_source(util::LuaSourceVec *sv, StreamBuffer *sb) { int count = sb->read_int32(); if ((count < 0) || (count > 10000)) throw StreamCorruption(); for (int i = 0; i < count; i++) { - std::string fn = sb->read_string(); - std::string code = sb->read_string(); + eng::string fn = sb->read_string(); + eng::string code = sb->read_string(); sv->emplace_back(fn, code); } } @@ -506,8 +506,8 @@ void SourceDB::register_lua_builtins() { auto regs = LuaFunctionReg::all(); for (LuaFunctionReg *reg : regs) { if (reg->get_func() == nullptr) { - std::string funcname; - std::string classname; + eng::string funcname; + eng::string classname; get_reg_name(reg, classname, funcname); if (classname.empty()) { LS.rawget(func, globals, funcname); @@ -529,7 +529,7 @@ void SourceDB::register_lua_builtins() { } -std::string SourceDB::function_docs(const LuaStack &LS0, LuaSlot fn) { +eng::string SourceDB::function_docs(const LuaStack &LS0, LuaSlot fn) { lua_State *L = LS0.state(); LuaVar sourcedb, fname, finfo, code; LuaStack LS(L, sourcedb, fname, finfo, code); @@ -540,12 +540,12 @@ std::string SourceDB::function_docs(const LuaStack &LS0, LuaSlot fn) { if (reg == nullptr) { return ""; } - std::string classname; - std::string funcname; + eng::string classname; + eng::string funcname; get_reg_name(reg, classname, funcname); - std::ostringstream oss; + eng::ostringstream oss; util::StringVec docs = util::split_docstring(reg->get_docs()); - for (const std::string &line : docs) { + for (const eng::string &line : docs) { oss << "-- " << line << std::endl; } oss << "function "; @@ -567,7 +567,7 @@ std::string SourceDB::function_docs(const LuaStack &LS0, LuaSlot fn) { } // Get the finfo table from the source db. - LS.set(fname, std::string(ar.short_src)); + LS.set(fname, eng::string(ar.short_src)); LS.rawget(finfo, sourcedb, fname); if (!LS.istable(finfo)) { return ""; @@ -591,7 +591,7 @@ std::string SourceDB::function_docs(const LuaStack &LS0, LuaSlot fn) { while ((linelo > 0) && (util::is_lua_comment(lines[linelo-1]))) linelo -= 1; // Output the docs. - std::ostringstream result; + eng::ostringstream result; for (int i = linelo; i <= linehi; i++) { result << lines[i] << std::endl; } diff --git a/luprex/core/cpp/source.hpp b/luprex/core/cpp/source.hpp index de263da6..60186ba3 100644 --- a/luprex/core/cpp/source.hpp +++ b/luprex/core/cpp/source.hpp @@ -150,7 +150,7 @@ public: // containing one error per line, and returned. If the return value // is the empty string, there were no errors. // - std::string rebuild(); + eng::string rebuild(); // Difference transmission. // @@ -173,14 +173,14 @@ public: // These functions are direct getters/setters for values in the source // database. They are intended only for unit testing. // - void set(const std::string &fn, const std::string &code, int sequence); - std::string get(const std::string &fn); + void set(const eng::string &fn, const eng::string &code, int sequence); + eng::string get(const eng::string &fn); // Add builtins to the global function registry. static void register_lua_builtins(); // Get function documentation. - static std::string function_docs(const LuaStack &LS, LuaSlot slot); + static eng::string function_docs(const LuaStack &LS, LuaSlot slot); // Serialize and unserialize a source vector. // diff --git a/luprex/core/cpp/streambuffer.cpp b/luprex/core/cpp/streambuffer.cpp index 3253f771..865a17d7 100644 --- a/luprex/core/cpp/streambuffer.cpp +++ b/luprex/core/cpp/streambuffer.cpp @@ -25,7 +25,7 @@ StreamBuffer::StreamBuffer() { StreamBuffer::StreamBuffer(int64_t size, bool fixed) { assert(size >= 0); - init(fixed, true, (char*)malloc(size), size); + init(fixed, true, (char*)dlmalloc(size), size); } StreamBuffer::StreamBuffer(const char *s, int64_t size) { @@ -34,13 +34,13 @@ StreamBuffer::StreamBuffer(const char *s, int64_t size) { write_cursor_ = buf_hi_; } -StreamBuffer::StreamBuffer(const std::string &src) { +StreamBuffer::StreamBuffer(const eng::string &src) { init(true, false, const_cast(src.c_str()), src.size()); write_cursor_ = buf_hi_; } StreamBuffer::~StreamBuffer() { - if (owned_ && (buf_lo_ != 0)) free(buf_lo_); + if (owned_ && (buf_lo_ != 0)) dlfree(buf_lo_); } int64_t StreamBuffer::total_reads() const { @@ -87,9 +87,9 @@ void StreamBuffer::make_space_slow(int64_t bytes) { } else if (existing_size >= desired_size) { if (data_size > 0) memcpy(buf_lo_, read_cursor_, data_size); } else { - char *nbuf = (char *)malloc(desired_size); + char *nbuf = (char *)dlmalloc(desired_size); if (data_size > 0) memcpy(nbuf, read_cursor_, data_size); - if (buf_lo_ != nullptr) free(buf_lo_); + if (buf_lo_ != nullptr) dlfree(buf_lo_); buf_lo_ = nbuf; buf_hi_ = nbuf + desired_size; } @@ -116,7 +116,7 @@ char *StreamBuffer::get_overwrite(int64_t size, int64_t write_count_after) { void StreamBuffer::clear() { assert(owned_); if (!fixed_size_) { - if (buf_lo_ != nullptr) free(buf_lo_); + if (buf_lo_ != nullptr) dlfree(buf_lo_); buf_lo_ = 0; buf_hi_ = 0; } @@ -128,14 +128,14 @@ void StreamBuffer::clear() { lua_reader_size_ = 0; } -std::string StreamBuffer::readline() { +eng::string StreamBuffer::readline() { char *p = read_cursor_; while ((p < write_cursor_) && (*p != '\n')) p++; if (p == write_cursor_) { return ""; } else { p++; - std::string result(read_cursor_, p - read_cursor_); + eng::string result(read_cursor_, p - read_cursor_); read_cursor_ = p; return result; } @@ -182,7 +182,7 @@ void StreamBuffer::write_bytes(const char *s, int64_t len) { write_cursor_ += len; } -void StreamBuffer::write_bytes(const std::string &s) { +void StreamBuffer::write_bytes(const eng::string &s) { write_bytes(s.c_str(), s.size()); } @@ -322,7 +322,7 @@ void StreamBuffer::write_hashvalue(const util::HashValue &hv) { write_uint64(hv.second); } -void StreamBuffer::write_string(const std::string &s) { +void StreamBuffer::write_string(const eng::string &s) { if (s.size() >= 255) { write_uint8(0xFF); write_uint64(s.size()); @@ -339,11 +339,11 @@ util::HashValue StreamBuffer::read_hashvalue() { return util::HashValue(f,s); } -std::string StreamBuffer::read_string() { +eng::string StreamBuffer::read_string() { return read_string_limit(0xFFFFFFF); } -std::string StreamBuffer::read_string_limit(int64_t max_allowed) { +eng::string StreamBuffer::read_string_limit(int64_t max_allowed) { int64_t len = read_uint8(); if (len == 255) { len = read_int64(); @@ -351,11 +351,11 @@ std::string StreamBuffer::read_string_limit(int64_t max_allowed) { if (len < 0) throw StreamCorruption(); if (len > max_allowed) throw StreamCorruption(); const char *bytes = read_bytes(len); - return std::string(bytes, len); + return eng::string(bytes, len); } -std::string StreamBuffer::read_entire_contents() { - std::string result(read_cursor_, fill()); +eng::string StreamBuffer::read_entire_contents() { + eng::string result(read_cursor_, fill()); read_cursor_ = write_cursor_; return result; } @@ -504,18 +504,18 @@ public: } }; -class StreamBufferOStream : public std::ostream { +class StreamBufferOStream : public eng::ostream { private: StreamBufferWriter writer_; public: - StreamBufferOStream(StreamBuffer *t) : std::ostream(nullptr), writer_(t) { + StreamBufferOStream(StreamBuffer *t) : eng::ostream(nullptr), writer_(t) { rdbuf(&writer_); } virtual ~StreamBufferOStream() { } }; -std::ostream &StreamBuffer::ostream() { +eng::ostream &StreamBuffer::ostream() { if (ostream_ == nullptr) { ostream_.reset(new StreamBufferOStream(this)); } diff --git a/luprex/core/cpp/streambuffer.hpp b/luprex/core/cpp/streambuffer.hpp index 7bef6576..a1d8a2e6 100644 --- a/luprex/core/cpp/streambuffer.hpp +++ b/luprex/core/cpp/streambuffer.hpp @@ -121,7 +121,7 @@ // try { // // Parse the message. // int32_t value1 = streambuffer.read_int32(); -// std::string value2 = streambuffer.read_string(maxlen); +// eng::string value2 = streambuffer.read_string(maxlen); // int64_t value3 = streambuffer.read_int64(); // // // Great! I got the whole message. @@ -252,7 +252,7 @@ public: StreamBuffer(const char *s, int64_t len); // Construct a streambuffer that reads from an external block of bytes. - StreamBuffer(const std::string &data); + StreamBuffer(const eng::string &data); // Delete a StreamBuffer. ~StreamBuffer(); @@ -276,7 +276,7 @@ public: // Attempt to do a "readline". If there is no newline in // the buffer, returns empty string. If there is a newline, // returns a block of text that ends in newline. - std::string readline(); + eng::string readline(); // Write block of bytes into the buffer. // @@ -284,7 +284,7 @@ public: // It just writes the bytes. // void write_bytes(const char *bytes, int64_t len); - void write_bytes(const std::string &bytes); + void write_bytes(const eng::string &bytes); // Read a block of bytes from the buffer. // @@ -333,7 +333,7 @@ public: // void write_bool(bool b) { write_int8(b ? 1 : 0); } void write_hashvalue(const util::HashValue &hv); - void write_string(const std::string &s); + void write_string(const eng::string &s); // Read other types from the buffer. // @@ -343,12 +343,12 @@ public: // bool read_bool() { return read_int8(); } util::HashValue read_hashvalue(); - std::string read_string(); - std::string read_string_limit(int64_t max_allowed); + eng::string read_string(); + eng::string read_string_limit(int64_t max_allowed); // Read the entire contents of the buffer as a string. // - std::string read_entire_contents(); + eng::string read_entire_contents(); // Overwrite values previously written to the buffer. // @@ -404,7 +404,7 @@ public: void *lua_reader_ud(int64_t bytes); // Get an ostream that writes into the StreamBuffer. - std::ostream &ostream(); + eng::ostream &ostream(); private: // Start and end of the allocated block. @@ -429,7 +429,7 @@ private: int64_t lua_reader_size_; // The ostream. Only allocated on demand. - std::unique_ptr ostream_; + eng::unique_ptr ostream_; // Initialize with a new buffer. void init(bool fixed, bool owned, char *buf, int64_t size); diff --git a/luprex/core/cpp/table.cpp b/luprex/core/cpp/table.cpp index 1661f9b7..51347772 100644 --- a/luprex/core/cpp/table.cpp +++ b/luprex/core/cpp/table.cpp @@ -233,7 +233,7 @@ LuaDefine(deque_create, "", "create a deque") { LuaVar classobj; LuaStack LS(L, rdeque, classobj); const int imax = 4; - std::string err = LS.getclass(classobj, "deque"); + eng::string err = LS.getclass(classobj, "deque"); if (err != "") { luaL_error(L, "Class deque has been corrupted"); } diff --git a/luprex/core/cpp/textgame.cpp b/luprex/core/cpp/textgame.cpp index f72868a8..a2b9146d 100644 --- a/luprex/core/cpp/textgame.cpp +++ b/luprex/core/cpp/textgame.cpp @@ -53,7 +53,7 @@ private: } void do_choose_command(const StringVec &cmd) { - std::string action = gui_.get_action(util::strtoint(cmd[1], -1)); + eng::string action = gui_.get_action(util::strtoint(cmd[1], -1)); if (action == "") { stdostream() << "Invalid menu item #" << std::endl; return; @@ -111,7 +111,7 @@ private: { world_->update_source(get_lua_source()); while (true) { - std::string line = get_stdio_channel()->in()->readline(); + eng::string line = get_stdio_channel()->in()->readline(); if (line == "") break; console_.add(line); get_stdio_channel()->set_prompt(console_.get_prompt()); diff --git a/luprex/core/cpp/two-mallocs.cpp b/luprex/core/cpp/two-mallocs.cpp index 1c586584..67b88dfb 100644 --- a/luprex/core/cpp/two-mallocs.cpp +++ b/luprex/core/cpp/two-mallocs.cpp @@ -57,7 +57,7 @@ int dlmalloc_hash() { hash = (hash * 17) + (int)(intptr_t)(blk); } for (int i = 0; i < 15; i++) { - free(blocks[i]); + dlfree(blocks[i]); } return (hash & 0x7FFFFFFF) | (0x40000000); } diff --git a/luprex/core/cpp/two-mallocs.hpp b/luprex/core/cpp/two-mallocs.hpp index 7dd89597..c3600993 100644 --- a/luprex/core/cpp/two-mallocs.hpp +++ b/luprex/core/cpp/two-mallocs.hpp @@ -54,25 +54,38 @@ bool operator!=(EngAllocator const&, EngAllocator const&) noexcept return false; } -// namespace eng { +// DrvAllocator: a class meant to be used as an STL Allocator. +// Causes objects to be allocated using malloc and free. +template +class DrvAllocator +{ +public: + using value_type = T; + DrvAllocator() noexcept {} + template DrvAllocator(DrvAllocator const&) noexcept {} -// template -// using hash = std::hash; + value_type* allocate(std::size_t n) + { + return static_cast(dlmalloc(n*sizeof(value_type))); + } -// template -// using less = std::less; + void deallocate(value_type* p, std::size_t) noexcept + { + dlfree(p); + } +}; -// template -// using equal_to = std::equal_to; +template +bool operator==(DrvAllocator const&, DrvAllocator const&) noexcept +{ + return true; +} -// template -// using char_traits = std::char_traits; +template +bool operator!=(DrvAllocator const&, DrvAllocator const&) noexcept +{ + return false; +} -// template -// using pair = std::pair; - - - -// } #endif // TWO_MALLOCS_HPP diff --git a/luprex/core/cpp/util.cpp b/luprex/core/cpp/util.cpp index 6c8be2ca..b61d0750 100644 --- a/luprex/core/cpp/util.cpp +++ b/luprex/core/cpp/util.cpp @@ -6,11 +6,11 @@ #include #include -#include #include #include #include #include +#include #ifdef WIN32 #endif @@ -30,7 +30,7 @@ static bool ascii_isdigit(char c) { return ((c >= '0') && (c <= '9')); } -bool is_identifier(const std::string &str) { +bool is_identifier(const eng::string &str) { if (str.size() == 0) return false; char c=str[0]; if ((!ascii_isalpha(c)) && (c!='_')) return false; @@ -41,7 +41,7 @@ bool is_identifier(const std::string &str) { return true; } -void quote_string(const std::string &s, std::ostream *os) { +void quote_string(const eng::string &s, eng::ostream *os) { bool anysq = false; bool anydq = false; for (char c : s) { @@ -82,8 +82,8 @@ IdVector id_vector_create(int64_t id1, int64_t id2, int64_t id3, int64_t id4) { return result; } -std::string id_vector_debug_string(const IdVector &idv) { - std::ostringstream oss; +eng::string id_vector_debug_string(const IdVector &idv) { + eng::ostringstream oss; bool first = true; for (int64_t id : idv) { if (!first) oss << ","; @@ -111,7 +111,7 @@ IdVector sort_union_id_vectors(const IdVector &v1, const IdVector &v2) { return result; } -HashValue hash_string(const std::string &s) { +HashValue hash_string(const eng::string &s) { uint64_t hash1 = 0; uint64_t hash2 = 0; SpookyHash::Hash128(s.c_str(), s.size(), &hash1, &hash2); @@ -125,14 +125,14 @@ HashValue hash_id_vector(const IdVector &idv) { return util::HashValue(hash1, hash2); } -std::string hash_to_hex(const HashValue &hv) { - std::ostringstream oss; +eng::string hash_to_hex(const HashValue &hv) { + eng::ostringstream oss; oss << std::hex << std::setw(16) << std::setfill('0') << hv.first; oss << std::hex << std::setw(16) << std::setfill('0') << hv.second; return oss.str(); } -StringVec split(const std::string &s, char sep) { +StringVec split(const eng::string &s, char sep) { StringVec result; int start = 0; for (int i = 0; i < int(s.size()); i++) { @@ -147,14 +147,14 @@ StringVec split(const std::string &s, char sep) { return result; } -static std::string substr_nocr(const std::string &s, int start, int len) { +static eng::string substr_nocr(const eng::string &s, int start, int len) { if ((len > 0) && (s[start + len - 1] == '\r')) { len -= 1; } return s.substr(start, len); } -StringVec split_lines(const std::string &s) { +StringVec split_lines(const eng::string &s) { StringVec result; int start = 0; for (int i = 0; i < int(s.size()); i++) { @@ -169,7 +169,7 @@ StringVec split_lines(const std::string &s) { return result; } -StringVec split_docstring(const std::string &s) { +StringVec split_docstring(const eng::string &s) { StringVec result; int start = 0; for (int i = 0; i < int(s.size()); i++) { @@ -187,9 +187,9 @@ StringVec split_docstring(const std::string &s) { return result; } -std::string join(const StringVec &strs, const std::string &sep) { +eng::string join(const StringVec &strs, const eng::string &sep) { if (strs.empty()) return ""; - std::ostringstream oss; + eng::ostringstream oss; oss << strs[0]; for (int i = 1; i < int(strs.size()); i++) { oss << sep << strs[i]; @@ -197,9 +197,9 @@ std::string join(const StringVec &strs, const std::string &sep) { return oss.str(); } -std::string repeat_string(const std::string &a, int n) { +eng::string repeat_string(const eng::string &a, int n) { int len = a.size(); - std::string result(len * n, ' '); + eng::string result(len * n, ' '); for (int i = 0; i < n; i++) { for (int j = 0; j < len; j++) { result[i*len + j] = a[j]; @@ -208,7 +208,7 @@ std::string repeat_string(const std::string &a, int n) { return result; } -int common_prefix_length(const std::string &a, const std::string &b) { +int common_prefix_length(const eng::string &a, const eng::string &b) { int minlen = std::min(a.size(), b.size()); for (int i = 0; i < minlen; i++) { if (a[i] != b[i]) return i; @@ -216,25 +216,25 @@ int common_prefix_length(const std::string &a, const std::string &b) { return minlen; } -std::string tolower(std::string input) { +eng::string tolower(eng::string input) { for (int i = 0; i < int(input.size()); i++) { input[i] = std::tolower(input[i]); } return input; } -std::string toupper(std::string input) { +eng::string toupper(eng::string input) { for (int i = 0; i < int(input.size()); i++) { input[i] = std::toupper(input[i]); } return input; } -bool has_prefix(const std::string &s, const std::string &prefix) { +bool has_prefix(const eng::string &s, const eng::string &prefix) { return 0 == s.compare(0, prefix.size(), prefix); } -bool has_suffix(const std::string &s, const std::string &suffix) { +bool has_suffix(const eng::string &s, const eng::string &suffix) { if (s.length() >= suffix.length()) { return (0 == s.compare (s.length() - suffix.length(), suffix.length(), suffix)); } else { @@ -242,14 +242,14 @@ bool has_suffix(const std::string &s, const std::string &suffix) { } } -bool validinteger(const std::string &value) { +bool validinteger(const eng::string &value) { char *endptr; if (value.size() == 0) return false; strtoll(value.c_str(), &endptr, 10); return (endptr == value.c_str() + value.size()); } -int64_t strtoint(const std::string &value, int64_t errval) { +int64_t strtoint(const eng::string &value, int64_t errval) { char *endptr; if (value.size() == 0) return errval; int64_t result = strtoll(value.c_str(), &endptr, 10); @@ -260,7 +260,7 @@ int64_t strtoint(const std::string &value, int64_t errval) { } } -double strtodouble(const std::string &value) { +double strtodouble(const eng::string &value) { char *endptr; if (value.size() == 0) return std::nan(""); double result = strtod(value.c_str(), &endptr); @@ -271,25 +271,25 @@ double strtodouble(const std::string &value) { } } -std::string_view sv_ltrim(std::string_view v) { +eng::string_view sv_ltrim(eng::string_view v) { const char *b = v.data(); const char *e = v.data() + v.size(); while ((e > b) && (std::isspace(b[0]))) { b++; } - return std::string_view(b, e-b); + return eng::string_view(b, e-b); } -std::string_view sv_rtrim(std::string_view v) { +eng::string_view sv_rtrim(eng::string_view v) { const char *b = v.data(); const char *e = v.data() + v.size(); while ((e > b) && (std::isspace(e[-1]))) { e--; } - return std::string_view(b, e-b); + return eng::string_view(b, e-b); } -std::string_view sv_trim(std::string_view v) { +eng::string_view sv_trim(eng::string_view v) { const char *b = v.data(); const char *e = v.data() + v.size(); while ((e > b) && (std::isspace(b[0]))) { @@ -298,25 +298,25 @@ std::string_view sv_trim(std::string_view v) { while ((e > b) && (std::isspace(e[-1]))) { e--; } - return std::string_view(b, e-b); + return eng::string_view(b, e-b); } -std::string ltrim(std::string_view v) { - return std::string(sv_ltrim(v)); +eng::string ltrim(eng::string_view v) { + return eng::string(sv_ltrim(v)); } -std::string rtrim(std::string_view v) { - return std::string(sv_rtrim(v)); +eng::string rtrim(eng::string_view v) { + return eng::string(sv_rtrim(v)); } -std::string trim(std::string_view v) { - return std::string(sv_trim(v)); +eng::string trim(eng::string_view v) { + return eng::string(sv_trim(v)); } -std::string_view sv_read_line(std::string_view &source) { +eng::string_view sv_read_line(eng::string_view &source) { size_t pos = source.find('\n'); - std::string_view result; - if (pos == std::string_view::npos) { + eng::string_view result; + if (pos == eng::string_view::npos) { result = source; source = ""; } else { @@ -342,43 +342,43 @@ bool world_type_authoritative(util::WorldType wt) { return (wt == WORLD_TYPE_MASTER) || (wt == WORLD_TYPE_STANDALONE); } -LuaSourcePtr make_lua_source(const std::string &code) { +LuaSourcePtr make_lua_source(const eng::string &code) { LuaSourcePtr result(new LuaSourceVec); - std::string fn = "file.lua"; + eng::string fn = "file.lua"; result->push_back(std::make_pair(fn, code)); return result; } -bool is_lua_comment(const std::string &s) { +bool is_lua_comment(const eng::string &s) { int start = 0; while ((start < int(s.size())) && ((s[start]==' ') || (s[start]=='\t'))) start++; return s.substr(start, 2) == "--"; } -std::string XYZ::debug_string() const { - std::ostringstream oss; +eng::string XYZ::debug_string() const { + eng::ostringstream oss; oss << "(" << x << "," << y << "," << z << ")"; return oss.str(); } } // namespace util -std::ostream &operator<<(std::ostream &oss, const util::hex64 &v) { +eng::ostream &operator<<(eng::ostream &oss, const util::hex64 &v) { oss << "0x" << std::setw(16) << std::setfill('0') << std::hex; return oss; } -std::ostream &operator<<(std::ostream &oss, const util::hex32 &v) { +eng::ostream &operator<<(eng::ostream &oss, const util::hex32 &v) { oss << "0x" << std::setw(8) << std::setfill('0') << std::hex; return oss; } -std::ostream &operator<<(std::ostream &oss, const util::hex16 &v) { +eng::ostream &operator<<(eng::ostream &oss, const util::hex16 &v) { oss << "0x" << std::setw(4) << std::setfill('0') << std::hex; return oss; } -std::ostream &operator<<(std::ostream &oss, const util::hex8 &v) { +eng::ostream &operator<<(eng::ostream &oss, const util::hex8 &v) { oss << "0x" << std::setw(2) << std::setfill('0') << std::hex; return oss; } @@ -449,10 +449,10 @@ LuaDefine(unittests_util, "", "some unit tests") { LuaAssert(L, util::trim("") == ""); // Test sv_read_line - std::string_view v = "foo\nbar\r\n"; - std::string_view v1 = util::sv_read_line(v); - std::string_view v2 = util::sv_read_line(v); - std::string_view v3 = util::sv_read_line(v); + eng::string_view v = "foo\nbar\r\n"; + eng::string_view v1 = util::sv_read_line(v); + eng::string_view v2 = util::sv_read_line(v); + eng::string_view v3 = util::sv_read_line(v); LuaAssertStrEq(L, v1, "foo"); LuaAssertStrEq(L, v2, "bar"); LuaAssertStrEq(L, v3, ""); diff --git a/luprex/core/cpp/util.hpp b/luprex/core/cpp/util.hpp index d807d979..b1f00bf0 100644 --- a/luprex/core/cpp/util.hpp +++ b/luprex/core/cpp/util.hpp @@ -30,88 +30,88 @@ enum MessageType { MSG_INVOKE, }; -using StringVec = std::vector; -using StringPair = std::pair; -using StringSet = std::set; -using LuaSourceVec = std::vector; -using LuaSourcePtr = std::unique_ptr; -using HashValue = std::pair; -using IdVector = std::vector; +using StringVec = eng::vector; +using StringPair = eng::pair; +using StringSet = eng::set; +using LuaSourceVec = eng::vector; +using LuaSourcePtr = eng::unique_ptr; +using HashValue = eng::pair; +using IdVector = eng::vector; // Return seconds elapsed, for profiling purposes. double profiling_clock(); // Return true if the string is a valid lua identifier. -bool is_identifier(const std::string &str); +bool is_identifier(const eng::string &str); // Output a string to a stream using Lua string escaping and quoting. -void quote_string(const std::string &str, std::ostream *os); +void quote_string(const eng::string &str, eng::ostream *os); // ID vector quick create. IdVector id_vector_create(int64_t id1=-1, int64_t id2=-1, int64_t id3=-1, int64_t id4=-1); // ID vector debug string. -std::string id_vector_debug_string(const IdVector &idv); +eng::string id_vector_debug_string(const IdVector &idv); // Unions and sorts two ID vectors. IdVector sort_union_id_vectors(const IdVector &v1, const IdVector &v2); // Get a 64-bit hashvalue for a string. -HashValue hash_string(const std::string &str); +HashValue hash_string(const eng::string &str); // Get a 64-bit hashvalue for an ID vector. HashValue hash_id_vector(const IdVector &idv); // Convert a hash to a hexadecimal string. -std::string hash_to_hex(const HashValue &hash); +eng::string hash_to_hex(const HashValue &hash); // Split a string into multiple strings -StringVec split(const std::string &s, char sep); +StringVec split(const eng::string &s, char sep); // Split a string into multiple strings using \r or \n -StringVec split_lines(const std::string &s); +StringVec split_lines(const eng::string &s); // Split a string into multiple lines using |, remove any leading blank line. -StringVec split_docstring(const std::string &s); +StringVec split_docstring(const eng::string &s); // Join multiple strings into one string -std::string join(const StringVec &strs, std::string sep); +eng::string join(const StringVec &strs, eng::string sep); // Return N repetitions of string A -std::string repeat_string(const std::string &a, int n); +eng::string repeat_string(const eng::string &a, int n); // Return the length of the common prefix of A and B. -int common_prefix_length(const std::string &a, const std::string &b); +int common_prefix_length(const eng::string &a, const eng::string &b); // String to lowercase/uppercase. Ascii only, no unicode. -std::string tolower(std::string input); -std::string toupper(std::string input); +eng::string tolower(eng::string input); +eng::string toupper(eng::string input); // Return true if the string has the specified prefix or suffix. -bool has_prefix(const std::string &s, const std::string &prefix); -bool has_suffix(const std::string &s, const std::string &suffix); +bool has_prefix(const eng::string &s, const eng::string &prefix); +bool has_suffix(const eng::string &s, const eng::string &suffix); // Return true if the string can be parsed as an integer. -bool validinteger(const std::string &value); +bool validinteger(const eng::string &value); // String to integer. Returns errval if the number is not parseable. -int64_t strtoint(const std::string &value, int64_t errval); +int64_t strtoint(const eng::string &value, int64_t errval); // String to double. Returns NAN if the number is not parseable. -double strtodouble(const std::string &value); +double strtodouble(const eng::string &value); // Trim a string_view -std::string_view sv_ltrim(std::string_view v); -std::string_view sv_rtrim(std::string_view v); -std::string_view sv_trim(std::string_view v); +eng::string_view sv_ltrim(eng::string_view v); +eng::string_view sv_rtrim(eng::string_view v); +eng::string_view sv_trim(eng::string_view v); // Trim strings: left end, right end, both ends. -std::string ltrim(std::string_view s); -std::string rtrim(std::string_view s); -std::string trim(std::string_view s); +eng::string ltrim(eng::string_view s); +eng::string rtrim(eng::string_view s); +eng::string trim(eng::string_view s); // Read a line from a string_view -std::string_view sv_read_line(std::string_view &source); +eng::string_view sv_read_line(eng::string_view &source); // Calculate distance between two points double distance_squared(double x1, double y1, double x2, double y2); @@ -120,15 +120,15 @@ double distance_squared(double x1, double y1, double x2, double y2); bool world_type_authoritative(util::WorldType wt); // Make a LuaSourceVec with one element, for unit testing. -LuaSourcePtr make_lua_source(const std::string &code); +LuaSourcePtr make_lua_source(const eng::string &code); // Return true if the line of code is a lua comment. -bool is_lua_comment(const std::string &line); +bool is_lua_comment(const eng::string &line); // Remove nullptrs from a vector of unique pointers. template -void remove_nullptrs(std::vector> &vec) { - std::unique_ptr nullp; +void remove_nullptrs(eng::vector> &vec) { + eng::unique_ptr nullp; auto iter = std::remove(vec.begin(), vec.end(), nullp); vec.erase(iter, vec.end()); } @@ -140,10 +140,10 @@ struct XYZ { XYZ(float ix, float iy, float iz) { x=ix; y=iy; z=iz; } bool operator ==(const XYZ &o) const { return x==o.x && y == o.y && z==o.z; } bool operator !=(const XYZ &o) const { return x!=o.x || y != o.y || z!=o.z; } - std::string debug_string() const; + eng::string debug_string() const; }; -// These are formatting directives that can be sent to a std::ostream. +// These are formatting directives that can be sent to a eng::ostream. class hex64 {}; class hex32 {}; class hex16 {}; @@ -157,9 +157,9 @@ public: } // namespace util -std::ostream &operator<<(std::ostream &oss, const util::hex64 &v); -std::ostream &operator<<(std::ostream &oss, const util::hex32 &v); -std::ostream &operator<<(std::ostream &oss, const util::hex16 &v); -std::ostream &operator<<(std::ostream &oss, const util::hex8 &v); +eng::ostream &operator<<(eng::ostream &oss, const util::hex64 &v); +eng::ostream &operator<<(eng::ostream &oss, const util::hex32 &v); +eng::ostream &operator<<(eng::ostream &oss, const util::hex16 &v); +eng::ostream &operator<<(eng::ostream &oss, const util::hex8 &v); #endif // UTIL_HPP diff --git a/luprex/core/cpp/world-accessor.cpp b/luprex/core/cpp/world-accessor.cpp index a0cbfaf6..217db425 100644 --- a/luprex/core/cpp/world-accessor.cpp +++ b/luprex/core/cpp/world-accessor.cpp @@ -80,7 +80,7 @@ LuaDefine(tangible_setclass, "tan,class", LuaStack LS(L, tanobj, classname, classtab, mt); World *w = World::fetch_global_pointer(L); w->tangible_get(LS, tanobj); - std::string err = LS.getclass(classtab, classname); + eng::string err = LS.getclass(classtab, classname); if (err != "") { luaL_error(L, "%s", err.c_str()); } @@ -101,7 +101,7 @@ LuaDefine(tangible_getclass, "tan", w->tangible_get(LS, tanobj); LS.getmetatable(mt, tanobj); LS.rawget(classtab, mt, "__index"); - std::string name = LS.classname(classtab); + eng::string name = LS.classname(classtab); if (name == "") { LS.set(classname, LuaNil); } else { @@ -139,7 +139,7 @@ LuaDefine(tangible_build, "configtable", LS.checktable(config); // Get the class of the new tangible. LS.rawget(classname, config, "class"); - std::string err = LS.getclass(classtab, classname); + eng::string err = LS.getclass(classtab, classname); if (err != "") { luaL_error(L, "%s", err.c_str()); } @@ -280,7 +280,7 @@ LuaDefine(tangible_scan, "plane,x,y,radius,omit_nowhere", LuaRet list; LuaStack LS(L, lplane, lx, ly, lradius, lomit_nowhere, list); World *w = World::fetch_global_pointer(L); - std::string plane = LS.ckstring(lplane); + eng::string plane = LS.ckstring(lplane); double x = LS.cknumber(lx); double y = LS.cknumber(ly); double radius = LS.cknumber(lradius); @@ -314,7 +314,7 @@ LuaDefine(tangible_nopredict, "", LuaDefine(pprint, "obj1,obj2,...", "|Pretty-print object or objects.") { World *w = World::fetch_global_pointer(L); - std::ostream *ostream = w->lthread_print_stream(); + eng::ostream *ostream = w->lthread_print_stream(); LuaStack LS(L); for (int i = 1; i <= lua_gettop(L); i++) { LuaSpecial root(i); @@ -327,7 +327,7 @@ LuaDefine(pprint, "obj1,obj2,...", LuaDefine(print, "obj1,obj2,...", "|Print object or objects.") { World *w = World::fetch_global_pointer(L); - std::ostream *ostream = w->lthread_print_stream(); + eng::ostream *ostream = w->lthread_print_stream(); LuaStack LS(L); int n = lua_gettop(L); for (int i = 1; i <= n; i++) { @@ -342,10 +342,10 @@ LuaDefine(print, "obj1,obj2,...", LuaDefine(doc, "function", "|Print documentation for specified function.") { World *w = World::fetch_global_pointer(L); - std::ostream *ostream = w->lthread_print_stream(); + eng::ostream *ostream = w->lthread_print_stream(); LuaArg func; LuaStack LS(L, func); - std::string doc = SourceDB::function_docs(LS, func); + eng::string doc = SourceDB::function_docs(LS, func); if (doc == "") { (*ostream) << "no doc found" << std::endl; } diff --git a/luprex/core/cpp/world-core.cpp b/luprex/core/cpp/world-core.cpp index 68b72891..c1e5d4ab 100644 --- a/luprex/core/cpp/world-core.cpp +++ b/luprex/core/cpp/world-core.cpp @@ -70,7 +70,7 @@ World::World(util::WorldType wt) { // Initialize the SourceDB. At this stage, the sourcedb is // empty, so it's just populating the lua builtins. source_db_.init(state()); - std::string srcerrs = source_db_.rebuild(); + eng::string srcerrs = source_db_.rebuild(); // Clear the clock. clock_ = 0; @@ -144,7 +144,7 @@ Tangible *World::tangible_get(const LuaStack &LS, LuaSlot tab) { return result; } -Tangible *World::tangible_make(lua_State *L, int64_t id, const std::string &plane, bool pushdb) { +Tangible *World::tangible_make(lua_State *L, int64_t id, const eng::string &plane, bool pushdb) { // Get a state if we don't already have one. if (L == nullptr) { L = state(); @@ -263,7 +263,7 @@ int64_t World::create_login_actor() { return tan->id(); } -std::string World::probe_lua(int64_t actor_id, const std::string &lua) { +eng::string World::probe_lua(int64_t actor_id, const eng::string &lua) { assert(stack_is_clear()); lua_State *L = state(); @@ -294,7 +294,7 @@ std::string World::probe_lua(int64_t actor_id, const std::string &lua) { // If there's an error message, print it. // Otherwise, pretty-print the results. - std::ostream *ostream = lthread_print_stream(); + eng::ostream *ostream = lthread_print_stream(); if (status == LUA_OK) { for (int i = top + 1; i <= lua_gettop(L); i++) { LuaSpecial root(i); @@ -311,7 +311,7 @@ std::string World::probe_lua(int64_t actor_id, const std::string &lua) { // Collect the lthread_prints (and also make sure they // don't go into the printbuffer). - std::string result = lthread_prints_->str(); + eng::string result = lthread_prints_->str(); lthread_prints_.reset(); close_lthread_state(); @@ -387,7 +387,7 @@ void World::update_source(const util::LuaSourceVec &source) { assert(stack_is_clear()); source_db_.update(source); assert(stack_is_clear()); - std::string errs = source_db_.rebuild(); + eng::string errs = source_db_.rebuild(); // I don't have a good place to send the error messages right // now. The engine needs a catch-all place to send errors that // occur at unexpected times. @@ -428,7 +428,7 @@ void World::invoke(const Invocation &inv) { } } -void World::invoke_flush_prints(int64_t actor_id, int64_t place_id, const std::string &action, const InvocationData &data) { +void World::invoke_flush_prints(int64_t actor_id, int64_t place_id, const eng::string &action, const InvocationData &data) { assert(stack_is_clear()); // Check argument sanity. if (actor_id != place_id) { @@ -448,7 +448,7 @@ void World::invoke_flush_prints(int64_t actor_id, int64_t place_id, const std::s -void World::invoke_lua(int64_t actor_id, int64_t place_id, const std::string &action, const InvocationData &data) { +void World::invoke_lua(int64_t actor_id, int64_t place_id, const eng::string &action, const InvocationData &data) { assert(stack_is_clear()); // Make sure that actor and place exist. @@ -519,7 +519,7 @@ void World::invoke_lua(int64_t actor_id, int64_t place_id, const std::string &ac assert(stack_is_clear()); } -void World::invoke_plan(int64_t actor_id, int64_t place_id, const std::string &action, const InvocationData &data) { +void World::invoke_plan(int64_t actor_id, int64_t place_id, const eng::string &action, const InvocationData &data) { assert(stack_is_clear()); // Validate that the action is legal. @@ -614,7 +614,7 @@ void World::invoke_plan(int64_t actor_id, int64_t place_id, const std::string &a assert(stack_is_clear()); } -void World::invoke_tick(int64_t actor_id, int64_t place_id, const std::string &action, const InvocationData &data) { +void World::invoke_tick(int64_t actor_id, int64_t place_id, const eng::string &action, const InvocationData &data) { if (!util::world_type_authoritative(world_type_)) { return; } @@ -622,7 +622,7 @@ void World::invoke_tick(int64_t actor_id, int64_t place_id, const std::string &a run_scheduled_threads(); } -void World::invoke_lua_source(int64_t actor_id, int64_t place_id, const std::string &action, const InvocationData &data) { +void World::invoke_lua_source(int64_t actor_id, int64_t place_id, const eng::string &action, const InvocationData &data) { if (!util::world_type_authoritative(world_type_)) { return; } @@ -683,7 +683,7 @@ void World::run_scheduled_threads() { lua_State *CO = LS.ckthread(thread); open_lthread_state(LS.ckinteger(actorid), sched.place_id(), LS.ckboolean(useppool), true); int status = lua_resume(CO, nullptr, LS.ckint(nargs)); - std::ostream *ostream = lthread_print_stream(); + eng::ostream *ostream = lthread_print_stream(); // Three possible outcomes: finished, yielded, or errored. if (!util::world_type_authoritative(world_type_)) { @@ -763,7 +763,7 @@ void World::open_lthread_state(int64_t actor, int64_t place, bool ppool, bool pr lthread_place_id_ = place; lthread_use_ppool_ = ppool; if (prints) { - lthread_prints_.reset(new std::ostringstream); + lthread_prints_.reset(new eng::ostringstream); } else { lthread_prints_.reset(); } @@ -775,7 +775,7 @@ void World::close_lthread_state() { // there isn't an actor, or if the actor doesn't have a PrintBuffer, // send the output to std::cerr. if (lthread_prints_ != nullptr) { - const std::string &output = lthread_prints_->str(); + const eng::string &output = lthread_prints_->str(); Tangible *actor = tangible_get(lthread_actor_id_); if (actor != nullptr) { bool auth = util::world_type_authoritative(world_type_); @@ -786,7 +786,7 @@ void World::close_lthread_state() { clear_lthread_state(); } -std::ostream *World::lthread_print_stream() const { +eng::ostream *World::lthread_print_stream() const { if (lthread_prints_ != nullptr) { return lthread_prints_.get(); } else { diff --git a/luprex/core/cpp/world-difftab.cpp b/luprex/core/cpp/world-difftab.cpp index fca08f80..1dad1037 100644 --- a/luprex/core/cpp/world-difftab.cpp +++ b/luprex/core/cpp/world-difftab.cpp @@ -135,7 +135,7 @@ static void transmit_value(LuaStack &MLS, LuaSlot mval, LuaSlot mtnmap, StreamBu } } -static void transmit_value_debug_string(StreamBuffer *sb, std::ostringstream &oss) { +static void transmit_value_debug_string(StreamBuffer *sb, eng::ostringstream &oss) { int kind = sb->read_uint8(); switch (kind) { case LUA_TBOOLEAN: { @@ -231,9 +231,9 @@ static bool diff_tables(LuaStack &SLS0, LuaSlot stnmap, LuaSlot stab, return (nupdates > 0); } -static std::string diff_tables_debug_string(StreamBuffer *sb) { - std::vector sorted; - std::ostringstream oss; +static eng::string diff_tables_debug_string(StreamBuffer *sb) { + eng::vector sorted; + eng::ostringstream oss; int ndiffs = sb->read_int32(); for (int i = 0; i < ndiffs; i++) { transmit_value_debug_string(sb, oss); @@ -243,7 +243,7 @@ static std::string diff_tables_debug_string(StreamBuffer *sb) { oss.str(""); } std::sort(sorted.begin(), sorted.end()); - for (const std::string &s : sorted) { + for (const eng::string &s : sorted) { oss << s << ";"; } return oss.str(); @@ -265,7 +265,7 @@ static void set_transmitted_value(LuaStack &LS, LuaSlot tangibles, LuaSlot ntmap return; } case LUA_TSTRING: { - std::string value = sb->read_string(); + eng::string value = sb->read_string(); DebugLine(dbc) << dbinfo << "'" << value << "'"; LS.set(target, value); return; @@ -277,7 +277,7 @@ static void set_transmitted_value(LuaStack &LS, LuaSlot tangibles, LuaSlot ntmap return; } case LUA_TT_CLASS: { - std::string value = sb->read_string(); + eng::string value = sb->read_string(); DebugLine(dbc) << dbinfo << "class " << value; LS.makeclass(target, value); return; diff --git a/luprex/core/cpp/world-diffxmit.cpp b/luprex/core/cpp/world-diffxmit.cpp index 3057282b..d353f46c 100644 --- a/luprex/core/cpp/world-diffxmit.cpp +++ b/luprex/core/cpp/world-diffxmit.cpp @@ -226,7 +226,7 @@ void World::patch_tanclass(StreamBuffer *sb, DebugCollector *dbc) { LS.rawget(tab, tangibles, id); assert(LS.istable(tab)); LS.getmetatable(meta, tab); - std::string name = sb->read_string(); + eng::string name = sb->read_string(); DebugLine(dbc) << "tanclass " << id << "=" << name; if (name == "") { LS.rawset(meta, "__index", LuaNil); @@ -261,8 +261,8 @@ void World::diff_tanclass(int64_t actor_id, World *master, StreamBuffer *xsb) { SLS.getmetatable(smeta, stab); MLS.rawget(mclass, mmeta, "__index"); SLS.rawget(sclass, smeta, "__index"); - std::string mname = MLS.classname(mclass); - std::string sname = SLS.classname(sclass); + eng::string mname = MLS.classname(mclass); + eng::string sname = SLS.classname(sclass); if (mname != sname) { tsb.write_int64(id); tsb.write_string(mname); @@ -283,7 +283,7 @@ void World::patch_source(StreamBuffer *sb, DebugCollector *dbc) { DebugBlock dbb(dbc, "patch_source"); bool modified = source_db_.patch(sb, dbc); if (modified) { - std::string errs = source_db_.rebuild(); + eng::string errs = source_db_.rebuild(); DebugLine(dbc) << "Source DB rebuilt"; // TODO: I don't currently have any good place to send the // error messages. This is a stopgap. diff --git a/luprex/core/cpp/world-pairtab.cpp b/luprex/core/cpp/world-pairtab.cpp index 7a163d5b..f6aab82a 100644 --- a/luprex/core/cpp/world-pairtab.cpp +++ b/luprex/core/cpp/world-pairtab.cpp @@ -103,7 +103,7 @@ void World::pair_lua_tables(const IdVector &basis, lua_State *master) { } // Keep track of which tables are already paired - std::vector paired; + eng::vector paired; paired.assign(s_ntables + 1, false); // This records the top of the stack. @@ -185,7 +185,7 @@ int World::number_remaining_tables(const IdVector &basis, lua_State *master) { LS.rawget(ntmap, LuaRegistry, "ntmap"); LS.rawget(tangibles, LuaRegistry, "tangibles"); int ntables = LS.rawlen(ntmap); - std::vector visited; + eng::vector visited; visited.assign(ntables + 1, false); int top = lua_gettop(L); diff --git a/luprex/core/cpp/world-testing.cpp b/luprex/core/cpp/world-testing.cpp index d127b104..785d6d65 100644 --- a/luprex/core/cpp/world-testing.cpp +++ b/luprex/core/cpp/world-testing.cpp @@ -14,21 +14,21 @@ void World::tangible_walkto(int64_t id, int64_t animid, float x, float y) { } -std::string World::tangible_anim_debug_string(int64_t id) const { +eng::string World::tangible_anim_debug_string(int64_t id) const { const Tangible *t = tangible_get(id); if (t == 0) return "no such tangible"; return t->anim_queue_.steps_debug_string(); } -std::string World::tangible_id_pool_debug_string(int64_t id) const { +eng::string World::tangible_id_pool_debug_string(int64_t id) const { const Tangible *t = tangible_get(id); if (t == 0) return "no such tangible"; return t->id_player_pool_.debug_string(); } -std::string World::tangible_ids_debug_string() const { +eng::string World::tangible_ids_debug_string() const { util::IdVector idv; for (const auto &pair : tangibles_) { idv.push_back(pair.first); @@ -37,8 +37,8 @@ std::string World::tangible_ids_debug_string() const { return util::id_vector_debug_string(idv); } -std::string World::tangibles_near_debug_string(int64_t actor, int64_t distance) { - std::ostringstream result; +eng::string World::tangibles_near_debug_string(int64_t actor, int64_t distance) { + eng::ostringstream result; for (int64_t id : get_near(actor, distance, true, false)) { const Tangible *tan = tangible_get(id); const AnimStep &aqback = tan->anim_queue_.back(); @@ -47,13 +47,13 @@ std::string World::tangibles_near_debug_string(int64_t actor, int64_t distance) return result.str(); } -std::string World::tangible_pprint(int64_t id) const { +eng::string World::tangible_pprint(int64_t id) const { lua_State *L = state(); LuaVar tangibles, tan, meta; LuaStack LS(L, tangibles, tan, meta); LS.rawget(tangibles, LuaRegistry, "tangibles"); LS.rawget(tan, tangibles, id); - std::ostringstream oss; + eng::ostringstream oss; if (LS.istable(tan)) { LS.getmetatable(meta, tan); LS.clearmetatable(tan); @@ -66,12 +66,12 @@ std::string World::tangible_pprint(int64_t id) const { return oss.str(); } -std::string World::numbered_tables_debug_string() const { +eng::string World::numbered_tables_debug_string() const { lua_State *L = state(); LuaVar ntmap, tab, tid; LuaStack LS(L, ntmap, tab, tid); - std::vector result; - std::ostringstream oss; + eng::vector result; + eng::ostringstream oss; // Fetch the numbered tables map. LS.rawget(ntmap, LuaRegistry, "ntmap"); @@ -90,19 +90,19 @@ std::string World::numbered_tables_debug_string() const { } LS.result(); std::sort(result.begin(), result.end()); - for (const std::string &s : result) { + for (const eng::string &s : result) { oss << s << ";"; } return oss.str(); } -std::string World::paired_tables_debug_string(lua_State *master) const { +eng::string World::paired_tables_debug_string(lua_State *master) const { lua_State *synch = state(); LuaVar mntmap, sntmap, mtab, stab, mtid, stid; LuaStack MLS(master, mntmap, mtab, mtid); LuaStack SLS(synch, sntmap, stab, stid); - std::vector> result; - std::ostringstream oss; + eng::vector> result; + eng::ostringstream oss; // Fetch the numbered tables map. MLS.rawget(mntmap, LuaRegistry, "ntmap"); @@ -115,8 +115,8 @@ std::string World::paired_tables_debug_string(lua_State *master) const { MLS.rawget(mtab, mntmap, i); SLS.rawget(stab, sntmap, i); if (MLS.istable(mtab) && SLS.istable(stab)) { - std::string mname = "unknown"; - std::string sname = "unknown"; + eng::string mname = "unknown"; + eng::string sname = "unknown"; MLS.rawget(mtid, mtab, "TID"); if (MLS.isstring(mtid)) { mname = MLS.ckstring(mtid); @@ -137,7 +137,7 @@ std::string World::paired_tables_debug_string(lua_State *master) const { return oss.str(); } -void World::tangible_set_string(int64_t id, const std::string &path, const std::string &value) { +void World::tangible_set_string(int64_t id, const eng::string &path, const eng::string &value) { lua_State *L = state(); LuaVar tangibles, tab, subtab; LuaStack LS(L, tangibles, tab, subtab); @@ -150,11 +150,11 @@ void World::tangible_set_string(int64_t id, const std::string &path, const std:: // Split the path parts into the table names and final part. util::StringVec pathparts = util::split(path, '.'); assert(pathparts.size() >= 1); - std::string finalpart = pathparts.back(); + eng::string finalpart = pathparts.back(); pathparts.pop_back(); // Create subtables as necessary. - for (const std::string &subname : pathparts) { + for (const eng::string &subname : pathparts) { LS.rawget(subtab, tab, subname); if (LS.isnil(subtab)) { LS.set(subtab, LuaNewTable); @@ -170,7 +170,7 @@ void World::tangible_set_string(int64_t id, const std::string &path, const std:: assert(stack_is_clear()); } -void World::tangible_copy_global(int64_t id, const std::string &path, const std::string &global) { +void World::tangible_copy_global(int64_t id, const eng::string &path, const eng::string &global) { lua_State *L = state(); LuaVar tangibles, tab, subtab, globtab, value; LuaStack LS(L, tangibles, tab, subtab, globtab, value); @@ -183,11 +183,11 @@ void World::tangible_copy_global(int64_t id, const std::string &path, const std: // Split the path parts into the table names and final part. util::StringVec pathparts = util::split(path, '.'); assert(pathparts.size() >= 1); - std::string finalpart = pathparts.back(); + eng::string finalpart = pathparts.back(); pathparts.pop_back(); // Create subtables as necessary. - for (const std::string &subname : pathparts) { + for (const eng::string &subname : pathparts) { LS.rawget(subtab, tab, subname); if (LS.isnil(subtab)) { LS.set(subtab, LuaNewTable); @@ -204,7 +204,7 @@ void World::tangible_copy_global(int64_t id, const std::string &path, const std: LS.result(); } -void World::tangible_set_class(int64_t id, const std::string &c) const { +void World::tangible_set_class(int64_t id, const eng::string &c) const { LuaVar tangibles, tan, meta, sclass; LuaStack LS(state(), tangibles, tan, meta, sclass); LS.rawget(tangibles, LuaRegistry, "tangibles"); @@ -220,7 +220,7 @@ void World::tangible_set_class(int64_t id, const std::string &c) const { LS.result(); } -std::string World::tangible_get_class(int64_t id) const { +eng::string World::tangible_get_class(int64_t id) const { LuaVar tangibles, tan, meta, sclass; LuaStack LS(state(), tangibles, tan, meta, sclass); LS.rawget(tangibles, LuaRegistry, "tangibles"); @@ -228,7 +228,7 @@ std::string World::tangible_get_class(int64_t id) const { assert(LS.istable(tan)); LS.getmetatable(meta, tan); LS.rawget(sclass, meta, "__index"); - std::string result = LS.classname(sclass); + eng::string result = LS.classname(sclass); LS.result(); return result; } diff --git a/luprex/core/cpp/world.hpp b/luprex/core/cpp/world.hpp index d0aa98fa..c084f495 100644 --- a/luprex/core/cpp/world.hpp +++ b/luprex/core/cpp/world.hpp @@ -87,13 +87,13 @@ public: void configure_id_pool_for_actor() { id_player_pool_.set_fifo_capacity(3); id_player_pool_.refill(); } }; -using UniqueTangible = std::unique_ptr; +using UniqueTangible = eng::unique_ptr; class World { public: using IdVector = util::IdVector; - using TanVector = std::vector; - using Redirects = std::map; + using TanVector = eng::vector; + using Redirects = eng::map; const float RadiusVisibility = 100.0; const float RadiusClose = 10.0; @@ -131,7 +131,7 @@ public: // the tangible's database onto the lua stack. Otherwise, leaves the lua // stack untouched. // - Tangible *tangible_make(lua_State *L, int64_t id, const std::string &plane, bool pushdb); + Tangible *tangible_make(lua_State *L, int64_t id, const eng::string &plane, bool pushdb); // Get a pointer to the specified tangible. // @@ -176,7 +176,7 @@ public: // from the stringstream. If the lua expression returns a // value, that is also printed to the stringstream. // - std::string probe_lua(int64_t actor_id, const std::string &lua); + eng::string probe_lua(int64_t actor_id, const eng::string &lua); // Probe the 'interface' function of the specified sprite. // @@ -247,7 +247,7 @@ public: void open_lthread_state(int64_t actor_id, int64_t place_id, bool ppool, bool prints); void close_lthread_state(); - std::ostream *lthread_print_stream() const; + eng::ostream *lthread_print_stream() const; // Allocate a single ID. // @@ -266,23 +266,23 @@ private: // Invoke a plan. // - void invoke_plan(int64_t actor_id, int64_t place_id, const std::string &action, const InvocationData &data); + void invoke_plan(int64_t actor_id, int64_t place_id, const eng::string &action, const InvocationData &data); // Invoke a lua string. // - void invoke_lua(int64_t actor_id, int64_t place_id, const std::string &action, const InvocationData &data); + void invoke_lua(int64_t actor_id, int64_t place_id, const eng::string &action, const InvocationData &data); // Invoke the flush-prints operation. // - void invoke_flush_prints(int64_t actor_id, int64_t place_id, const std::string &action, const InvocationData &data); + void invoke_flush_prints(int64_t actor_id, int64_t place_id, const eng::string &action, const InvocationData &data); // Invoke the tick operation. // - void invoke_tick(int64_t actor_id, int64_t place_id, const std::string &action, const InvocationData &data); + void invoke_tick(int64_t actor_id, int64_t place_id, const eng::string &action, const InvocationData &data); // Invoke the lua_source operation. // - void invoke_lua_source(int64_t actor_id, int64_t place_id, const std::string &action, const InvocationData &data); + void invoke_lua_source(int64_t actor_id, int64_t place_id, const eng::string &action, const InvocationData &data); public: //////////////////////////////////////////////////////////////////////////// @@ -300,49 +300,49 @@ public: // Get the tangible's animation queue as a debug string. // - std::string tangible_anim_debug_string(int64_t id) const; + eng::string tangible_anim_debug_string(int64_t id) const; // Get the tangible's ID Pool as a debug string. // - std::string tangible_id_pool_debug_string(int64_t id) const; + eng::string tangible_id_pool_debug_string(int64_t id) const; // Get a list of all existing tangibles as a comma-separated string. // - std::string tangible_ids_debug_string() const; + eng::string tangible_ids_debug_string() const; // Get a list of all tangibles near the target as a string. // - std::string tangibles_near_debug_string(int64_t actor, int64_t distance); + eng::string tangibles_near_debug_string(int64_t actor, int64_t distance); // Shows the TID (table ID) of the tables that were numbered. // TIDs are in alphabetical order. Any table without a TID // shows up as "unknown" // - std::string numbered_tables_debug_string() const; + eng::string numbered_tables_debug_string() const; // Paired tables debug string. Shows TID=TID pairs, sorted alphabetically. // - std::string paired_tables_debug_string(lua_State *master) const; + eng::string paired_tables_debug_string(lua_State *master) const; // Store a string in the tangible's database. // - void tangible_set_string(int64_t id, const std::string &path, const std::string &value); + void tangible_set_string(int64_t id, const eng::string &path, const eng::string &value); // Copy a lua global variable into the tangible's database. // - void tangible_copy_global(int64_t id, const std::string &path, const std::string &global); + void tangible_copy_global(int64_t id, const eng::string &path, const eng::string &global); // Pretty-print the entire tangible database and return it as a string. // - std::string tangible_pprint(int64_t id) const; + eng::string tangible_pprint(int64_t id) const; // Set the tangible's lua class. // - void tangible_set_class(int64_t id, const std::string &c) const; + void tangible_set_class(int64_t id, const eng::string &c) const; // Get the tangible's lua class (returns empty string if none). // - std::string tangible_get_class(int64_t id) const; + eng::string tangible_get_class(int64_t id) const; public: @@ -467,7 +467,7 @@ private: // Tangibles table. // - std::unordered_map tangibles_; + eng::unordered_map tangibles_; // Current time. int64_t clock_; @@ -489,7 +489,7 @@ private: int64_t lthread_actor_id_; int64_t lthread_place_id_; int64_t lthread_use_ppool_; - std::unique_ptr lthread_prints_; + eng::unique_ptr lthread_prints_; friend class Tangible; friend int lfn_tangible_animate(lua_State *L); @@ -502,7 +502,7 @@ private: friend int lfn_tangible_scan(lua_State *L); }; -using UniqueWorld = std::unique_ptr; +using UniqueWorld = eng::unique_ptr; #endif // WORLD_HPP diff --git a/luprex/core/wrap/wrap-deque.hpp b/luprex/core/wrap/wrap-deque.hpp index 2da70f1d..e5ea7ef1 100644 --- a/luprex/core/wrap/wrap-deque.hpp +++ b/luprex/core/wrap/wrap-deque.hpp @@ -11,7 +11,7 @@ using deque = std::deque>; namespace drv { template -using deque = std::deque>; +using deque = std::deque>; } // namespace drv #endif // WRAP_DEQUE_HPP diff --git a/luprex/core/wrap/wrap-map.hpp b/luprex/core/wrap/wrap-map.hpp index 3d45ad25..217e2bcd 100644 --- a/luprex/core/wrap/wrap-map.hpp +++ b/luprex/core/wrap/wrap-map.hpp @@ -19,7 +19,7 @@ using less = std::less; template using pair = std::pair; template> -using map = std::map>>; +using map = std::map>>; } // namespace drv #endif // WRAP_MAP_HPP diff --git a/luprex/core/wrap/wrap-set.hpp b/luprex/core/wrap/wrap-set.hpp index 205482ff..8f4cf4bd 100644 --- a/luprex/core/wrap/wrap-set.hpp +++ b/luprex/core/wrap/wrap-set.hpp @@ -15,7 +15,7 @@ namespace drv { template using less = std::less; template> -using set = std::set>; +using set = std::set>; } // namespace drv #endif // WRAP_SET_HPP diff --git a/luprex/core/wrap/wrap-sstream.hpp b/luprex/core/wrap/wrap-sstream.hpp index 84db092c..d0fa6a1d 100644 --- a/luprex/core/wrap/wrap-sstream.hpp +++ b/luprex/core/wrap/wrap-sstream.hpp @@ -7,13 +7,13 @@ namespace eng { template> using basic_ostringstream = std::basic_ostringstream>; -using ostringstream = std::basic_ostringstream; +using ostringstream = basic_ostringstream; } // namespace eng namespace drv { template> -using basic_ostringstream = std::basic_ostringstream>; -using ostringstream = std::basic_ostringstream; +using basic_ostringstream = std::basic_ostringstream>; +using ostringstream = basic_ostringstream; } // namespace drv #endif // WRAP_SSTREAM_HPP diff --git a/luprex/core/wrap/wrap-string.hpp b/luprex/core/wrap/wrap-string.hpp index 4af14b4a..2f39b78c 100644 --- a/luprex/core/wrap/wrap-string.hpp +++ b/luprex/core/wrap/wrap-string.hpp @@ -12,7 +12,7 @@ using string = basic_string; namespace drv { template> -using basic_string = std::basic_string>; +using basic_string = std::basic_string>; using string = basic_string; } // namespace drv diff --git a/luprex/core/wrap/wrap-unordered-map.hpp b/luprex/core/wrap/wrap-unordered-map.hpp index b2e5c1a7..52468db9 100644 --- a/luprex/core/wrap/wrap-unordered-map.hpp +++ b/luprex/core/wrap/wrap-unordered-map.hpp @@ -23,7 +23,7 @@ using equal_to = std::equal_to; template using pair = std::pair; template, class E=std::equal_to> -using unordered_map = std::unordered_map>>; +using unordered_map = std::unordered_map>>; } // namespace drv #endif // WRAP_UNORDERED_MAP_HPP diff --git a/luprex/core/wrap/wrap-unordered-set.hpp b/luprex/core/wrap/wrap-unordered-set.hpp index 4c2d414f..f0a7b983 100644 --- a/luprex/core/wrap/wrap-unordered-set.hpp +++ b/luprex/core/wrap/wrap-unordered-set.hpp @@ -19,7 +19,7 @@ using hash = std::hash; template using equal_to = std::equal_to; template, class E=std::equal_to> -using unordered_set = std::unordered_set>; +using unordered_set = std::unordered_set>; } // namespace drv #endif // WRAP_UNORDERED_SET_HPP diff --git a/luprex/core/wrap/wrap-utility.hpp b/luprex/core/wrap/wrap-utility.hpp index 2aadc0ed..da986561 100644 --- a/luprex/core/wrap/wrap-utility.hpp +++ b/luprex/core/wrap/wrap-utility.hpp @@ -7,11 +7,15 @@ namespace eng { template using pair = std::pair; +template< class T1, class T2 > +constexpr std::pair make_pair( T1&& t, T2&& u ) { return std::make_pair(t,u); } } // namespace eng namespace drv { template using pair = std::pair; +template< class T1, class T2 > +constexpr std::pair make_pair( T1&& t, T2&& u ) { return std::make_pair(t,u); } } // namespace drv #endif // WRAP_UTILITY_HPP diff --git a/luprex/core/wrap/wrap-vector.hpp b/luprex/core/wrap/wrap-vector.hpp index 8ee5daa6..b53e29ca 100644 --- a/luprex/core/wrap/wrap-vector.hpp +++ b/luprex/core/wrap/wrap-vector.hpp @@ -11,7 +11,7 @@ using vector = std::vector>; namespace drv { template -using vector = std::vector>; +using vector = std::vector>; } // namespace drv #endif // WRAP_VECTOR_HPP