Skip to content

Commit c35cc07

Browse files
committed
fix #207
1 parent 1100b18 commit c35cc07

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

build/luasocket/inet.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
#ifdef _WIN32
2626
#define LUASOCKET_INET_PTON
27+
#else
28+
#define inet_pton_w32 inet_pton
2729
#endif
2830

2931
int inet_open(lua_State *L);

build/xlua.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,29 @@ LUA_API void xlua_pushcstable(lua_State *L, unsigned int size, int meta_ref) {
830830
lua_setmetatable(L, -2);
831831
}
832832

833+
LUA_API void xlua_pushstructbyptr(lua_State *L, void *ptr, unsigned int size, int meta_ref) {
834+
CSharpStruct *css = (CSharpStruct *)lua_newuserdata(L, size + sizeof(int) + sizeof(unsigned int));
835+
css->fake_id = -1;
836+
css->len = size;
837+
memcpy(css->data, ptr, size);
838+
lua_rawgeti(L, LUA_REGISTRYINDEX, meta_ref);
839+
lua_setmetatable(L, -2);
840+
}
841+
842+
LUALIB_API void xlua_getstructbyptr(lua_State *L, int index, void *ptr) {
843+
CSharpStruct *css = (CSharpStruct *)lua_touserdata(L, index);
844+
if (css != NULL && css->fake_id == -1) {
845+
memcpy(ptr, css->data, css->len);
846+
}
847+
}
848+
849+
LUALIB_API void xlua_updatestructbyptr(lua_State *L, int index, void *ptr) {
850+
CSharpStruct *css = (CSharpStruct *)lua_touserdata(L, index);
851+
if (css != NULL && css->fake_id == -1) {
852+
memcpy(css->data, ptr, css->len);
853+
}
854+
}
855+
833856
LUA_API int xlua_gettypeid(lua_State *L, int idx) {
834857
int type_id = -1;
835858
if (lua_type(L, idx) == LUA_TUSERDATA) {

0 commit comments

Comments
 (0)