@@ -830,6 +830,29 @@ LUA_API void xlua_pushcstable(lua_State *L, unsigned int size, int meta_ref) {
830
830
lua_setmetatable (L , -2 );
831
831
}
832
832
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
+
833
856
LUA_API int xlua_gettypeid (lua_State * L , int idx ) {
834
857
int type_id = -1 ;
835
858
if (lua_type (L , idx ) == LUA_TUSERDATA ) {
0 commit comments