diff --git a/3rd/lua-seri/lua-seri.c b/3rd/lua-seri/lua-seri.cpp similarity index 97% rename from 3rd/lua-seri/lua-seri.c rename to 3rd/lua-seri/lua-seri.cpp index 7aee9bdb..84caad3f 100644 --- a/3rd/lua-seri/lua-seri.c +++ b/3rd/lua-seri/lua-seri.cpp @@ -8,8 +8,12 @@ #endif -#include -#include +#ifdef __cplusplus +# include +#else +# include +# include +#endif #include #include #include @@ -92,14 +96,14 @@ struct read_block { inline static struct block * blk_alloc(void) { - struct block *b = malloc(sizeof(struct block)); + struct block *b = (struct block *)malloc(sizeof(struct block)); b->next = NULL; return b; } static inline void wb_push(struct write_block *b, const void *buf, int sz) { - const char * buffer = buf; + const char * buffer = (const char *)buf; if (b->ptr == BLOCK_SIZE) { _again: b->current = b->current->next = blk_alloc(); @@ -355,7 +359,7 @@ mark_table(lua_State *L, struct write_block *b, int index) { } if (id < MAX_REFERENCE) { b->r[id].object = obj; - b->r[id].address = addr; + b->r[id].address = (uint8_t*)addr; } else { ++id; lua_pushinteger(L, id); @@ -383,12 +387,12 @@ wb_table(lua_State *L, struct write_block *wb, int index) { static int ref_ancestor(lua_State *L, struct write_block *b, int index) { struct stack *s = &b->s; - int n = s->depth; - if (n == 0 || n >= MAX_DEPTH) + int depth = s->depth; + if (depth == 0 || depth >= MAX_DEPTH) return 0; int i; const void * obj = lua_topointer(L, index); - for (i=n-1;i>=0;i--) { + for (i=depth-1;i>=0;i--) { const void * ancestor = lua_topointer(L, s->ancestor[i]); if (ancestor == obj) { uint8_t n = COMBINE_TYPE(TYPE_REF, i); @@ -610,7 +614,7 @@ static void unpack_one(lua_State *L, struct read_block *rb); static int get_extend_integer(lua_State *L, struct read_block *rb) { uint8_t type; - const uint8_t *t = rb_read(rb, sizeof(type)); + const uint8_t *t = (const uint8_t *)rb_read(rb, sizeof(type)); if (t==NULL) { invalid_stream(L,rb); } @@ -752,7 +756,7 @@ push_value(lua_State *L, struct read_block *rb, int type, int cookie) { static void unpack_one(lua_State *L, struct read_block *rb) { uint8_t type; - const uint8_t *t = rb_read(rb, sizeof(type)); + const uint8_t *t = (const uint8_t *)rb_read(rb, sizeof(type)); if (t==NULL) { invalid_stream(L, rb); } @@ -762,7 +766,7 @@ unpack_one(lua_State *L, struct read_block *rb) { static void * seri(struct block *b, int len) { - uint8_t * buffer = malloc(len + 4); + uint8_t * buffer = (uint8_t *)malloc(len + 4); memcpy(buffer, &len, 4); // write length uint8_t * ptr = buffer + 4; while(len>0) { @@ -797,7 +801,7 @@ seri_unpack(lua_State *L, void *buffer) { luaL_checkstack(L,LUA_MINSTACK,NULL); } uint8_t type = 0; - const uint8_t *t = rb_read(&rb, sizeof(type)); + const uint8_t *t = (const uint8_t *)rb_read(&rb, sizeof(type)); if (t==NULL) break; type = *t; diff --git a/3rd/lua-seri/lua-seri.h b/3rd/lua-seri/lua-seri.h index 56f3d84f..0e764540 100644 --- a/3rd/lua-seri/lua-seri.h +++ b/3rd/lua-seri/lua-seri.h @@ -1,11 +1,8 @@ -#ifndef LUA_SERIALIZE_H -#define LUA_SERIALIZE_H +#pragma once -#include +struct lua_State; int seri_unpack(lua_State* L, void* buffer); int seri_unpackptr(lua_State* L, void* buffer); void * seri_pack(lua_State* L, int from, int* sz); void * seri_packstring(const char* str, int sz); - -#endif diff --git a/binding/lua_channel.cpp b/binding/lua_channel.cpp index ecf3a59c..26c14e43 100644 --- a/binding/lua_channel.cpp +++ b/binding/lua_channel.cpp @@ -1,3 +1,4 @@ +#include <3rd/lua-seri/lua-seri.h> #include #include #include @@ -12,10 +13,6 @@ #include #include -extern "C" { -#include <3rd/lua-seri/lua-seri.h> -} - namespace bee::lua_channel { class channel { public: diff --git a/binding/lua_serialization.cpp b/binding/lua_serialization.cpp index 43897fa4..2294617b 100644 --- a/binding/lua_serialization.cpp +++ b/binding/lua_serialization.cpp @@ -1,10 +1,7 @@ +#include <3rd/lua-seri/lua-seri.h> #include #include -extern "C" { -#include <3rd/lua-seri/lua-seri.h> -} - namespace bee::lua_serialization { static int unpack(lua_State* L) { switch (lua_type(L, 1)) { diff --git a/binding/lua_thread.cpp b/binding/lua_thread.cpp index e00333c9..e90ffe67 100644 --- a/binding/lua_thread.cpp +++ b/binding/lua_thread.cpp @@ -1,3 +1,4 @@ +#include <3rd/lua-seri/lua-seri.h> #include #include #include @@ -11,10 +12,6 @@ #include #include -extern "C" { -#include <3rd/lua-seri/lua-seri.h> -} - namespace bee::lua_thread { static const char* errmsg(lua_State* L, int idx) { const char* msg = lua_tostring(L, idx); diff --git a/compile/common.lua b/compile/common.lua index 50cceaf3..75c215ce 100644 --- a/compile/common.lua +++ b/compile/common.lua @@ -67,7 +67,7 @@ if lm.sanitize then end lm:lua_src "source_bee" { - sources = "3rd/lua-seri/lua-seri.c", + sources = "3rd/lua-seri/lua-seri.cpp", msvc = { flags = "/wd4244" }