Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why data can be written at an offset memory location? #83

Closed
sniper00 opened this issue Aug 5, 2022 · 1 comment
Closed

Why data can be written at an offset memory location? #83

sniper00 opened this issue Aug 5, 2022 · 1 comment

Comments

@sniper00
Copy link

sniper00 commented Aug 5, 2022

        private void SetExtraObject<T>(T obj, bool weak) where T : class
        {
            var handle = GCHandle.Alloc(obj, weak ? GCHandleType.Weak : GCHandleType.Normal);
            IntPtr extraSpace = _luaState - IntPtr.Size;
            Marshal.WriteIntPtr(extraSpace, GCHandle.ToIntPtr(handle));
        }
@sniper00 sniper00 closed this as completed Aug 5, 2022
@sniper00
Copy link
Author

sniper00 commented Aug 5, 2022

/*
** thread state + extra space
*/
typedef struct LX {
lu_byte extra_[LUA_EXTRASPACE];
lua_State l;
} LX;

/*
** Main thread combines a thread state and the global state
*/
typedef struct LG {
LX l;
global_State g;
} LG;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant