Can I call a function with its hexadecimal memory address?

Hello, hope you are doing well,

I was just wondering, is it possible to call a function with its hexadecimal memory address? If you don’t understand what I mean, when you try and print a function like so:

print(function() return "Hello" end)

It will print out something like this:
image
So what I’m asking is, can you do something like this?

0x515c5b41972f263f()

Because when I try it in studio, it always gives me an error.
I have looked on the DevForum for a while and I haven’t found anything like this.

Cheers,
somejtohguyman

I actually havent researched this, but well how you called it is surely not how you would call it.

Maybe there is a different way we dont yet know about, but I doubt it, because as you can see:
image
You cannot really recreate it, because it’s a function type.

1 Like

There are no ways of accessing system memory from Lua by addressing it that way, so no. Outside Roblox you could do it by interoperating with C code, but that’s not available to Roblox Lua.

Do you need it for something? There’s probably another way

1 Like

This hex representation of the function is not the actual address; before printing a function/userdata, it passes through a mapping (I presume for security reasons), so the only thing you can be sure of is that if the representation is the same, then it’s the same function.
See lua_encodepointer in Luau source code:

uintptr_t lua_encodepointer(lua_State* L, uintptr_t p)
{
    global_State* g = L->global;
    return uintptr_t((g->ptrenckey[0] * p + g->ptrenckey[2]) ^ (g->ptrenckey[1] * p + g->ptrenckey[3]));
}
4 Likes

I would give you all the solution, but sadly that isn’t possible. Thanks to everyone that helped!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.