Skip to content

Commit 76f759a

Browse files
committed
fixup
1 parent e05393d commit 76f759a

File tree

6 files changed

+57
-53
lines changed

6 files changed

+57
-53
lines changed

3rdparty/yasio/yasio/bindings/lyasio.cpp

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ enum
3939
};
4040

4141
template <typename _Stream>
42-
static void obstream_write_v(_Stream* obs, cxx17::string_view val, int length_field_bits)
42+
static void obstream_write_v(_Stream* obs, std::string_view val, int length_field_bits)
4343
{
4444
// default: Use variant length of length field, just like .net BinaryWriter.Write(String),
4545
// see:
@@ -58,7 +58,7 @@ static void obstream_write_v(_Stream* obs, cxx17::string_view val, int length_fi
5858
}
5959
};
6060
template <typename _Stream>
61-
static cxx17::string_view ibstream_read_v(_Stream* ibs, int length_field_bits)
61+
static std::string_view ibstream_read_v(_Stream* ibs, int length_field_bits)
6262
{
6363
// default: Use variant length of length field, just like .net BinaryReader.ReadString,
6464
// see:
@@ -113,21 +113,21 @@ static void register_obstream(sol::table& lib, const char* usertype)
113113
"write_f16", &_Stream::template write<fp16_t>,
114114
# endif
115115
"write_f", &_Stream::template write<float>, "write_lf", &_Stream::template write<double>, "write_v",
116-
[](_Stream* obs, cxx17::string_view sv, sol::variadic_args args) {
116+
[](_Stream* obs, std::string_view sv, sol::variadic_args args) {
117117
int lfl = -1;
118118
if (args.size() > 0)
119119
lfl = static_cast<int>(args[0]);
120120
return obstream_write_v<_Stream>(obs, sv, lfl);
121121
},
122-
"write_bytes", static_cast<void (_Stream::*)(cxx17::string_view)>(&_Stream::write_bytes), "length", &_Stream::length, "to_string",
123-
[](_Stream* obs) { return cxx17::string_view(obs->data(), obs->length()); }, "save", &_Stream::save);
122+
"write_bytes", static_cast<void (_Stream::*)(std::string_view)>(&_Stream::write_bytes), "length", &_Stream::length, "to_string",
123+
[](_Stream* obs) { return std::string_view(obs->data(), obs->length()); }, "save", &_Stream::save);
124124
}
125125

126126
template <typename _Stream, typename _StreamView, typename _OStream>
127127
static void register_ibstream(sol::table& lib, const char* usertype)
128128
{
129129
lib.new_usertype<_Stream>(
130-
usertype, sol::constructors<_Stream(), _Stream(yasio::sbyte_buffer), _Stream(const _OStream*)>(), "load", &_Stream::load, "read_ix",
130+
usertype, sol::constructors<_Stream(), _Stream(tlx::sbyte_buffer), _Stream(const _OStream*)>(), "load", &_Stream::load, "read_ix",
131131
&_Stream::template read_ix<int64_t>, "read_bool", &_Stream::template read<bool>, "read_i8", &_Stream::template read<int8_t>, "read_i16",
132132
&_Stream::template read<int16_t>, "read_i32", &_Stream::template read<int32_t>, "read_i64", &_Stream::template read<int64_t>, "read_u8",
133133
&_Stream::template read<uint8_t>, "read_u16", &_Stream::template read<uint16_t>, "read_u32", &_Stream::template read<uint32_t>, "read_u64",
@@ -142,8 +142,8 @@ static void register_ibstream(sol::table& lib, const char* usertype)
142142
lfl = static_cast<int>(args[0]);
143143
return ibstream_read_v<_Stream>(ibs, lfl);
144144
},
145-
"read_bytes", static_cast<cxx17::string_view (_Stream::*)(int)>(&_Stream::read_bytes), "seek", &_StreamView::seek, "length", &_StreamView::length,
146-
"to_string", [](_Stream* ibs) { return cxx17::string_view(ibs->data(), ibs->length()); });
145+
"read_bytes", static_cast<std::string_view (_Stream::*)(int)>(&_Stream::read_bytes), "seek", &_StreamView::seek, "length", &_StreamView::length,
146+
"to_string", [](_Stream* ibs) { return std::string_view(ibs->data(), ibs->length()); });
147147
}
148148
} // namespace lyasio
149149

@@ -170,11 +170,11 @@ YASIO_LUA_API int luaopen_yasio(lua_State* L)
170170
switch (buffer_type)
171171
{
172172
case lyasio::BUFFER_RAW:
173-
return sol::make_object(L, cxx17::string_view{packet_data(pkt), packet_len(pkt)});
173+
return sol::make_object(L, std::string_view{packet_data(pkt), packet_len(pkt)});
174174
case lyasio::BUFFER_FAST:
175-
return sol::make_object(L, cxx14::make_unique<yasio::fast_ibstream>(forward_packet((packet_t &&) pkt)));
175+
return sol::make_object(L, std::make_unique<yasio::fast_ibstream>(forward_packet((packet_t &&) pkt)));
176176
default:
177-
return sol::make_object(L, cxx14::make_unique<yasio::ibstream>(forward_packet((packet_t &&) pkt)));
177+
return sol::make_object(L, std::make_unique<yasio::ibstream>(forward_packet((packet_t &&) pkt)));
178178
}
179179
},
180180
"cindex", &io_event::cindex, "transport", &io_event::transport
@@ -192,13 +192,13 @@ YASIO_LUA_API int luaopen_yasio(lua_State* L)
192192
std::vector<io_hostent> hosts;
193193
auto host = channel_eps["host"];
194194
if (host.valid())
195-
hosts.push_back(io_hostent(host.get<cxx17::string_view>(), channel_eps["port"]));
195+
hosts.push_back(io_hostent(host.get<std::string_view>(), channel_eps["port"]));
196196
else
197197
{
198198
for (auto item : channel_eps)
199199
{
200200
auto ep = item.second.as<sol::table>();
201-
hosts.push_back(io_hostent(ep["host"].get<cxx17::string_view>(), ep["port"]));
201+
hosts.push_back(io_hostent(ep["host"].get<std::string_view>(), ep["port"]));
202202
}
203203
}
204204
return new (&uninitialized_memory)
@@ -258,16 +258,16 @@ YASIO_LUA_API int luaopen_yasio(lua_State* L)
258258
sol::overload(static_cast<void (io_service::*)(transport_handle_t)>(&io_service::close), static_cast<void (io_service::*)(int)>(&io_service::close)),
259259
"write",
260260
sol::overload(
261-
[](io_service* service, transport_handle_t transport, cxx17::string_view s) {
262-
return service->write(transport, yasio::sbyte_buffer{s.data(), s.data() + s.length()});
261+
[](io_service* service, transport_handle_t transport, std::string_view s) {
262+
return service->write(transport, tlx::sbyte_buffer{s.data(), s.data() + s.length()});
263263
},
264264
[](io_service* service, transport_handle_t transport, yasio::obstream* obs) { return service->write(transport, std::move(obs->buffer())); }),
265265
"write_to",
266266
sol::overload(
267-
[](io_service* service, transport_handle_t transport, cxx17::string_view s, cxx17::string_view ip, u_short port) {
268-
return service->write_to(transport, yasio::sbyte_buffer{s.data(), s.data() + s.length()}, ip::endpoint{ip.data(), port});
267+
[](io_service* service, transport_handle_t transport, std::string_view s, std::string_view ip, u_short port) {
268+
return service->write_to(transport, tlx::sbyte_buffer{s.data(), s.data() + s.length()}, ip::endpoint{ip.data(), port});
269269
},
270-
[](io_service* service, transport_handle_t transport, yasio::obstream* obs, cxx17::string_view ip, u_short port) {
270+
[](io_service* service, transport_handle_t transport, yasio::obstream* obs, std::string_view ip, u_short port) {
271271
return service->write_to(transport, std::move(obs->buffer()), ip::endpoint{ip.data(), port});
272272
}),
273273
"native_ptr", [](io_service* service) { return (void*)service; });
@@ -280,8 +280,8 @@ YASIO_LUA_API int luaopen_yasio(lua_State* L)
280280
lyasio::register_ibstream<ibstream, ibstream_view, obstream>(yasio_lib, "ibstream");
281281
lyasio::register_ibstream<fast_ibstream, fast_ibstream_view, fast_obstream>(yasio_lib, "fast_ibstream");
282282

283-
yasio_lib["highp_clock"] = &highp_clock<yasio::steady_clock_t>;
284-
yasio_lib["highp_time"] = &highp_clock<yasio::system_clock_t>;
283+
yasio_lib["highp_clock"] = &tlx::highp_clock<tlx::steady_clock_t>;
284+
yasio_lib["highp_time"] = &tlx::highp_clock<tlx::system_clock_t>;
285285

286286
yasio_lib["unwrap_ptr"] = [](lua_State* L) -> int {
287287
auto& pkt = *(packet_t*)lua_touserdata(L, 1);
@@ -371,19 +371,19 @@ YASIO_LUA_API int luaopen_yasio(lua_State* L)
371371
/// customize the type conversion from/to lua
372372
namespace kaguya
373373
{
374-
// cxx17::string_view
374+
// std::string_view
375375
template <>
376-
struct lua_type_traits<cxx17::string_view> {
377-
typedef cxx17::string_view get_type;
378-
typedef cxx17::string_view push_type;
376+
struct lua_type_traits<std::string_view> {
377+
typedef std::string_view get_type;
378+
typedef std::string_view push_type;
379379

380380
static bool strictCheckType(lua_State* l, int index) { return lua_type(l, index) == LUA_TSTRING; }
381381
static bool checkType(lua_State* l, int index) { return lua_isstring(l, index) != 0; }
382382
static get_type get(lua_State* l, int index)
383383
{
384384
size_t size = 0;
385385
const char* buffer = lua_tolstring(l, index, &size);
386-
return cxx17::string_view(buffer, size);
386+
return std::string_view(buffer, size);
387387
}
388388
static int push(lua_State* l, push_type s)
389389
{
@@ -527,15 +527,15 @@ static void register_obstream(kaguya::LuaTable& lib, const char* usertype, const
527527
.addFunction("write_f", &_BaseStream::template write<float>)
528528
.addFunction("write_lf", &_BaseStream::template write<double>)
529529
.addStaticFunction("write_v",
530-
[](_BaseStream* obs, cxx17::string_view sv, kaguya::VariadicArgType args) {
530+
[](_BaseStream* obs, std::string_view sv, kaguya::VariadicArgType args) {
531531
int lfl = -1;
532532
if (args.size() > 0)
533533
lfl = static_cast<int>(args[0]);
534534
return lyasio::obstream_write_v(obs, sv, lfl);
535535
})
536-
.addFunction("write_bytes", static_cast<void (_BaseStream::*)(cxx17::string_view)>(&_BaseStream::write_bytes))
536+
.addFunction("write_bytes", static_cast<void (_BaseStream::*)(std::string_view)>(&_BaseStream::write_bytes))
537537
.addFunction("length", &_BaseStream::length)
538-
.addStaticFunction("to_string", [](_BaseStream* obs) { return cxx17::string_view(obs->data(), obs->length()); }));
538+
.addStaticFunction("to_string", [](_BaseStream* obs) { return std::string_view(obs->data(), obs->length()); }));
539539
// ##-- obstream
540540
lib[usertype].setClass(userclass);
541541
}
@@ -565,10 +565,10 @@ static void register_ibstream(kaguya::LuaTable& lib, const char* usertype, const
565565
length_field_bits = static_cast<int>(args[0]);
566566
return lyasio::ibstream_read_v(ibs, length_field_bits);
567567
})
568-
.addFunction("read_bytes", static_cast<cxx17::string_view (_StreamView::*)(int)>(&_StreamView::read_bytes))
568+
.addFunction("read_bytes", static_cast<std::string_view (_StreamView::*)(int)>(&_StreamView::read_bytes))
569569
.addFunction("seek", &_StreamView::seek)
570570
.addFunction("length", &_StreamView::length)
571-
.addStaticFunction("to_string", [](_StreamView* ibs) { return cxx17::string_view(ibs->data(), ibs->length()); }));
571+
.addStaticFunction("to_string", [](_StreamView* ibs) { return std::string_view(ibs->data(), ibs->length()); }));
572572

573573
// ##-- ibstream
574574
lib[usertype].setClass(userclass);
@@ -602,8 +602,8 @@ YASIO_LUA_API int luaopen_yasio(lua_State* L)
602602
[](io_event* ev) {
603603
auto& pkt = ev->packet();
604604
if (is_packet_empty(pkt))
605-
return cxx17::string_view{""};
606-
return cxx17::string_view{packet_data(pkt), packet_len(pkt)};
605+
return std::string_view{""};
606+
return std::string_view{packet_data(pkt), packet_len(pkt)};
607607
})
608608
.addStaticFunction("fast_packet",
609609
[](io_event* ev) {
@@ -652,16 +652,16 @@ end
652652
static_cast<void (io_service::*)(int)>(&io_service::close))
653653
.addOverloadedFunctions(
654654
"write",
655-
[](io_service* service, transport_handle_t transport, cxx17::string_view s) {
655+
[](io_service* service, transport_handle_t transport, std::string_view s) {
656656
return service->write(transport, yasio::sbyte_buffer(s.data(), s.data() + s.length()));
657657
},
658658
[](io_service* service, transport_handle_t transport, yasio::obstream* obs) { return service->write(transport, std::move(obs->buffer())); })
659659
.addOverloadedFunctions(
660660
"write_to",
661-
[](io_service* service, transport_handle_t transport, cxx17::string_view s, cxx17::string_view ip, u_short port) {
661+
[](io_service* service, transport_handle_t transport, std::string_view s, std::string_view ip, u_short port) {
662662
return service->write_to(transport, yasio::sbyte_buffer(s.data(), s.data() + s.length()), ip::endpoint{ip.data(), port});
663663
},
664-
[](io_service* service, transport_handle_t transport, yasio::obstream* obs, cxx17::string_view ip, u_short port) {
664+
[](io_service* service, transport_handle_t transport, yasio::obstream* obs, std::string_view ip, u_short port) {
665665
return service->write_to(transport, std::move(obs->buffer()), ip::endpoint{ip.data(), port});
666666
})
667667
.addStaticFunction("set_option",

3rdparty/yasio/yasio/bindings/yasio_axlua.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ SOFTWARE.
3030
#include "yasio/bindings/yasio_axlua.hpp"
3131
#include "yasio/bindings/lyasio.hpp"
3232
#include "yasio/object_pool.hpp"
33-
#include "yasio/ref_ptr.hpp"
34-
#include "yasio/string_view.hpp"
3533

3634
// A workaround to fix compile issue caused by `CCPlatformMacros.h` doesn't handle `__has_attribute` it properly
3735
# if !__has_attribute(format)
@@ -40,6 +38,7 @@ SOFTWARE.
4038

4139
#include "axmol/base/Director.h"
4240
#include "axmol/base/Scheduler.h"
41+
#include "axmol/tlx/memory.hpp"
4342

4443
using namespace ax;
4544

@@ -63,15 +62,23 @@ struct TimerObject
6362
static uintptr_t s_timerId;
6463

6564
DEFINE_FAST_OBJECT_POOL_ALLOCATION(TimerObject, 128)
66-
YASIO__DEFINE_REFERENCE_CLASS
65+
66+
void retain() { ++_referenceCount; }
67+
void release()
68+
{
69+
if (--_referenceCount == 0)
70+
delete this;
71+
}
72+
73+
uint32_t _referenceCount{1};
6774
};
6875
uintptr_t TimerObject::s_timerId = 0;
6976

7077
static TIMER_ID loop(unsigned int n, float interval, vcallback_t callback)
7178
{
7279
if (n > 0 && interval >= 0)
7380
{
74-
yasio::ref_ptr<TimerObject> timerObj(new TimerObject(std::move(callback)));
81+
tlx::retain_ptr<TimerObject> timerObj(new TimerObject(std::move(callback)), tlx::adopt_object);
7582

7683
auto timerId = reinterpret_cast<TIMER_ID>(++TimerObject::s_timerId);
7784

@@ -93,7 +100,7 @@ static TIMER_ID delay(float delay, vcallback_t callback)
93100
{
94101
if (delay > 0)
95102
{
96-
yasio::ref_ptr<TimerObject> timerObj(new TimerObject(std::move(callback)));
103+
tlx::retain_ptr<TimerObject> timerObj(new TimerObject(std::move(callback)), tlx::adopt_object);
97104
auto timerId = reinterpret_cast<TIMER_ID>(++TimerObject::s_timerId);
98105

99106
std::string key = fmt::format("LSTMR#{}", fmt::ptr(timerId));

extensions/scripting/lua-bindings/manual/AxluaLoader.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ THE SOFTWARE.
3131
#include "lua-bindings/manual/LuaStack.h"
3232
#include "lua-bindings/manual/LuaEngine.h"
3333
#include "axmol/platform/FileUtils.h"
34-
#include "yasio/string_view.hpp"
3534

3635
using namespace ax;
3736

extensions/scripting/lua-bindings/manual/LuaBasicConversions.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include <sstream>
3131

3232
std::unordered_map<uintptr_t, const char*> g_luaType;
33-
std::unordered_map<cxx17::string_view, const char*> g_typeCast;
33+
std::unordered_map<std::string_view, const char*> g_typeCast;
3434

3535
#if _AX_DEBUG >= 1
3636
void luaval_to_native_err(lua_State* L, const char* msg, tolua_Error* err, const char* funcName)
@@ -229,7 +229,7 @@ bool luaval_to_std_string(lua_State* L, int lo, std::string* outValue, const cha
229229
return ok;
230230
}
231231

232-
bool luaval_to_std_string_view(lua_State* L, int lo, cxx17::string_view* outValue, const char* funcName)
232+
bool luaval_to_std_string_view(lua_State* L, int lo, std::string_view* outValue, const char* funcName)
233233
{
234234
if (NULL == L || NULL == outValue)
235235
return false;
@@ -249,7 +249,7 @@ bool luaval_to_std_string_view(lua_State* L, int lo, cxx17::string_view* outValu
249249
{
250250
size_t size;
251251
auto rawString = lua_tolstring(L, lo, &size);
252-
*outValue = cxx17::string_view(rawString, size);
252+
*outValue = std::string_view(rawString, size);
253253
}
254254

255255
return ok;

extensions/scripting/lua-bindings/manual/LuaBasicConversions.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,12 @@
4646
#include "axmol/rhi/VertexLayout.h"
4747
#include "axmol/ui/GUIDefine.h"
4848

49-
#include "yasio/string_view.hpp"
5049
#include <thread>
5150

5251
using namespace ax;
5352

5453
extern std::unordered_map<uintptr_t, const char*> g_luaType;
55-
extern std::unordered_map<cxx17::string_view, const char*> g_typeCast;
54+
extern std::unordered_map<std::string_view, const char*> g_typeCast;
5655

5756
#if _AX_DEBUG >= 1
5857
void luaval_to_native_err(lua_State* L, const char* msg, tolua_Error* err, const char* funcName = "");
@@ -187,7 +186,7 @@ extern bool luaval_to_long_long(lua_State* L, int lo, long long* outValue, const
187186
* string, otherwise return false.
188187
*/
189188
extern bool luaval_to_std_string(lua_State* L, int lo, std::string* outValue, const char* funcName = "");
190-
extern bool luaval_to_std_string_view(lua_State* L, int lo, cxx17::string_view* outValue, const char* funcName = "");
189+
extern bool luaval_to_std_string_view(lua_State* L, int lo, std::string_view* outValue, const char* funcName = "");
191190

192191
/**
193192
* Get a ssize_t value from the given acceptable index of stack.
@@ -1012,7 +1011,7 @@ const char* getLuaTypeName(T* ret, const char* defaultTypeName)
10121011
}
10131012
else
10141013
{ // unlike logic, for windows dll only
1015-
cxx17::string_view strkey(typeName);
1014+
std::string_view strkey(typeName);
10161015
auto iter2 = g_typeCast.find(strkey);
10171016
if (iter2 != g_typeCast.end())
10181017
{

extensions/scripting/lua-bindings/manual/LuaStack.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -670,9 +670,8 @@ int LuaStack::luaLoadChunksFromZIP(lua_State* L)
670670
return 0;
671671
}
672672

673-
using namespace cxx17;
674-
const auto BYTECODE_FILE_EXT = ".luac"_sv;
675-
const auto NOT_BYTECODE_FILE_EXT = ".lua"_sv;
673+
const auto BYTECODE_FILE_EXT = ".luac"sv;
674+
const auto NOT_BYTECODE_FILE_EXT = ".lua"sv;
676675

677676
const char* zipFilename = lua_tostring(L, -1);
678677
lua_settop(L, 0);
@@ -703,8 +702,8 @@ int LuaStack::luaLoadChunksFromZIP(lua_State* L)
703702
if (pos != std::string::npos)
704703
{
705704
std::string suffix = filename.substr(pos, filename.length());
706-
if (cxx17::string_view{suffix} == NOT_BYTECODE_FILE_EXT ||
707-
cxx17::string_view{suffix} == BYTECODE_FILE_EXT)
705+
if (std::string_view{suffix} == NOT_BYTECODE_FILE_EXT ||
706+
std::string_view{suffix} == BYTECODE_FILE_EXT)
708707
{
709708
filename.erase(pos);
710709
}

0 commit comments

Comments
 (0)