RoStrap / Classes

Enumerations and PseudoInstances (Robloxesque class system)
https://rostrap.github.io
MIT License
2 stars 1 forks source link

Question and what's the purpose of Empty() #19

Open karl-police opened 5 months ago

karl-police commented 5 months ago

idk, someone that I know told me to look at stuff, then I found this

no clue what this all is but once I saw the name "PseudoInstance", I immediately took a look at it, but already walked away when I saw that it uses all the Libraries that Roblox uses, e.g. Janitor and the entire _Index thing. (I wish I'd know how people even find these things, I feel like they all got this told from a Roblox Staff themselves)

Eitherways.

What's the purpose, of this: https://github.com/RoStrap/Classes/blob/75737c728ada5f86ab88fcf3ca9b79de52eb0086/PseudoInstance.lua#L19

Is this part of the magic like these mysterious libraries that just appear in stuff like DataStore Editor Plugin and etc. and NevermoreEngine, like... who advertised these libraries, how did people end up using it, and why is there a reference of node-js in Lua.

Validark commented 5 months ago

Well, I can tell you how I found out about Janitor. I created it as an alternative to Quenty's "Maid" library. The RoStrap project itself was heavily inspired by NevermoreEngine. Actually it was supposed to be a revision of NevermoreEngine, but things ended up going in a different direction. I found out about NevermoreEngine by searching on GitHub for quality Roblox Lua codebases.

Nowadays, I would encourage you to join the Roblox OSS community: https://discord.gg/ZBaF9xUXcH You can also find different libraries on the Roblox DevForum: https://devforum.roblox.com/


Empty is used in this part of the file:

https://github.com/RoStrap/Classes/blob/75737c728ada5f86ab88fcf3ca9b79de52eb0086/PseudoInstance.lua#L191-L196

Other pieces of code want to call a function when an event occurs, so rather than doing:

local callback = Events[event_name]
if callback ~= nil then
    callback()
end

I just guarantee that there is a callable function there so I can do:

Events[event_name]()

When it comes to metamethods, you can read about them here: https://create.roblox.com/docs/luau/metatables

Luau is also open-source, so you could read the source code if desired: https://github.com/luau-lang/luau Back in the day, I did read the Lua source code to learn how things work, but I also probed at Roblox's implementation with things like:

local Userdata = newproxy(true)

setmetatable(getmetatable(Userdata), {
    __index = function(_, i)
        error("Cannot access " .. i)
    end
})

typeof(Userdata)