Categories > Coding > Lua >

How do you hook metatables with the WRD API?

Posts: 18

Threads: 10

Joined: Jul, 2019

Reputation: 0

Posted

There are getrawmetatable() and setrawmetatable() methods in the API, along with setreadonly(). None of these methods appear to work or just cause my client to crash. Is there a specific way to use them? The way they are used in the Synapse documentation does not appear to work with WRD API.

  • 0

DeepPain

Wyvern

Posts: 475

Threads: 5

Joined: Jul, 2020

Reputation: 55

Replied

Just incase someone says "theres no newcclosure" they're stupid

it's a wrapper, all the functions are cclosures.

Anyway this is how:

local mt = getrawmetatable(game)
local backup = mt.__index
setreadonly(mt, false)

mt.__index = newcclosure(function(...) --newcclosure isnt needed here but it would be needed for any other execution method
    --do whatever here
    return backup(...)
end)
setreadonly(mt, true) --not needed but I like to do it
  • 0

My Discord is xwyvern

https://i.imgur.com/mH521VR.png

Posts: 18

Threads: 10

Joined: Jul, 2019

Reputation: 0

Replied

@DeepPain

Ran your origional, the block failed with an error:

attempt to call global 'newcclosure' (a nil value)

 

Removing the newcclosure, it would fail to run the code block upon indexing game (i put a print statement, and then a WRDApi console log)

 

WRD API simply does not support newcclosure, and as I stated in the question, the usage from Synapse X is inconsistent with WRD API.

  • 0

Wabz

Winning.js

Posts: 2406

Threads: 194

Joined: Apr, 2020

Reputation: 27

Replied

@snekerator well deeppain said all funcs on wrappers are cclosures so you could be doing this:

if newcclosure == nil then
    getgenv().newcclosure = function(func)
        func()
    end
end

I am not sure if it works and I might be totally wrong, but maybe it will work?

(add the code b4 ur script)

  • 0

My new discord is Wabz#1337 with ID 777154062789509130

DeepPain

Wyvern

Posts: 475

Threads: 5

Joined: Jul, 2020

Reputation: 55

Replied

@Wabz You'd need to return it not call it

  • 0

My Discord is xwyvern

https://i.imgur.com/mH521VR.png

Wabz

Winning.js

Posts: 2406

Threads: 194

Joined: Apr, 2020

Reputation: 27

Replied

@DeepPain oh ok

  • 0

My new discord is Wabz#1337 with ID 777154062789509130

Posts: 18

Threads: 10

Joined: Jul, 2019

Reputation: 0

Replied

@Wabz

Neither method works.

  • 0

bIoodhoundss

trashoundss

Posts: 11

Threads: 2

Joined: Feb, 2021

Reputation: 1

Replied

Molly rocks in my green tea

So uh what we talking bout?

  • 0

COME BACK THISNAMENOTGONE

Posts: 724

Threads: 58

Joined: Feb, 2021

Reputation: 3

Replied

What you guys think of funny monkey gif?

  • 0

no

Error: The signature must be between 3-200 characters

Users viewing this thread:

( Members: 0, Guests: 1, Total: 1 )