Commit 49a2107c authored by Chen Bill's avatar Chen Bill

include <cstring>

parent 32fb1c71
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
* Author: Argon * Author: Argon
*/ */
#include <cstring>
#include "duel.h" #include "duel.h"
#include "interpreter.h" #include "interpreter.h"
#include "field.h" #include "field.h"
...@@ -13,6 +14,14 @@ ...@@ -13,6 +14,14 @@
#include "group.h" #include "group.h"
#include "ocgapi.h" #include "ocgapi.h"
inline void write_buffer_vector(std::vector<byte>& buffer, const void* data, int size) {
if (size > 0) {
const auto len = buffer.size();
buffer.resize(len + size);
std::memcpy(&buffer[len], data, size);
}
}
duel::duel() { duel::duel() {
lua = new interpreter(this); lua = new interpreter(this);
game_field = new field(this); game_field = new field(this);
......
...@@ -19,14 +19,6 @@ class effect; ...@@ -19,14 +19,6 @@ class effect;
class field; class field;
class interpreter; class interpreter;
inline void write_buffer_vector(std::vector<byte>& buffer, const void* data, int size) {
if (size > 0) {
const auto len = buffer.size();
buffer.resize(len + size);
std::memcpy(&buffer[len], data, size);
}
}
class duel { class duel {
public: public:
using card_set = std::set<card*, card_sort>; using card_set = std::set<card*, card_sort>;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
* Author: Argon * Author: Argon
*/ */
#include <cstring>
#include "duel.h" #include "duel.h"
#include "group.h" #include "group.h"
#include "card.h" #include "card.h"
...@@ -17,7 +18,7 @@ interpreter::interpreter(duel* pd): coroutines(256) { ...@@ -17,7 +18,7 @@ interpreter::interpreter(duel* pd): coroutines(256) {
lua_state = luaL_newstate(); lua_state = luaL_newstate();
current_state = lua_state; current_state = lua_state;
pduel = pd; pduel = pd;
memcpy(lua_getextraspace(lua_state), &pd, LUA_EXTRASPACE); //set_duel_info std::memcpy(lua_getextraspace(lua_state), &pd, LUA_EXTRASPACE); //set_duel_info
no_action = 0; no_action = 0;
call_depth = 0; call_depth = 0;
//Initial //Initial
...@@ -663,6 +664,6 @@ int32 interpreter::get_function_handle(lua_State* L, int32 index) { ...@@ -663,6 +664,6 @@ int32 interpreter::get_function_handle(lua_State* L, int32 index) {
} }
duel* interpreter::get_duel_info(lua_State * L) { duel* interpreter::get_duel_info(lua_State * L) {
duel* pduel; duel* pduel;
memcpy(&pduel, lua_getextraspace(L), LUA_EXTRASPACE); std::memcpy(&pduel, lua_getextraspace(L), LUA_EXTRASPACE);
return pduel; return pduel;
} }
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include <list> #include <list>
#include <vector> #include <vector>
#include <cstdio> #include <cstdio>
#include <cstring>
class card; class card;
class effect; class effect;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* Author: Argon * Author: Argon
*/ */
#include <string.h> #include <cstring>
#include "scriptlib.h" #include "scriptlib.h"
#include "duel.h" #include "duel.h"
#include "field.h" #include "field.h"
...@@ -170,7 +170,7 @@ int32 scriptlib::debug_set_ai_name(lua_State *L) { ...@@ -170,7 +170,7 @@ int32 scriptlib::debug_set_ai_name(lua_State *L) {
duel* pduel = interpreter::get_duel_info(L); duel* pduel = interpreter::get_duel_info(L);
pduel->write_buffer8(MSG_AI_NAME); pduel->write_buffer8(MSG_AI_NAME);
const char* pstr = lua_tostring(L, 1); const char* pstr = lua_tostring(L, 1);
int len = (int)strlen(pstr); int len = (int)std::strlen(pstr);
if(len > 100) if(len > 100)
len = 100; len = 100;
pduel->write_buffer16(len); pduel->write_buffer16(len);
...@@ -184,7 +184,7 @@ int32 scriptlib::debug_show_hint(lua_State *L) { ...@@ -184,7 +184,7 @@ int32 scriptlib::debug_show_hint(lua_State *L) {
duel* pduel = interpreter::get_duel_info(L); duel* pduel = interpreter::get_duel_info(L);
pduel->write_buffer8(MSG_SHOW_HINT); pduel->write_buffer8(MSG_SHOW_HINT);
const char* pstr = lua_tostring(L, 1); const char* pstr = lua_tostring(L, 1);
int len = (int)strlen(pstr); int len = (int)std::strlen(pstr);
if(len > 1024) if(len > 1024)
len = 1024; len = 1024;
pduel->write_buffer16(len); pduel->write_buffer16(len);
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* Author: Argon * Author: Argon
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <cstring>
#include "ocgapi.h" #include "ocgapi.h"
#include "duel.h" #include "duel.h"
#include "card.h" #include "card.h"
...@@ -120,7 +120,7 @@ extern "C" DECL_DLLEXPORT void set_player_info(intptr_t pduel, int32 playerid, i ...@@ -120,7 +120,7 @@ extern "C" DECL_DLLEXPORT void set_player_info(intptr_t pduel, int32 playerid, i
pd->game_field->player[playerid].draw_count = drawcount; pd->game_field->player[playerid].draw_count = drawcount;
} }
extern "C" DECL_DLLEXPORT void get_log_message(intptr_t pduel, byte* buf) { extern "C" DECL_DLLEXPORT void get_log_message(intptr_t pduel, byte* buf) {
strcpy((char*)buf, ((duel*)pduel)->strbuffer); std::strcpy((char*)buf, ((duel*)pduel)->strbuffer);
} }
extern "C" DECL_DLLEXPORT int32 get_message(intptr_t pduel, byte* buf) { extern "C" DECL_DLLEXPORT int32 get_message(intptr_t pduel, byte* buf) {
int32 len = ((duel*)pduel)->read_buffer(buf); int32 len = ((duel*)pduel)->read_buffer(buf);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment