generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Table Challenge [Moderate]

Previous Thread :: Next Thread 
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
27 Apr 2015 10:34 PM
Create a read-only table.
Report Abuse
Viscoelastic is not online. Viscoelastic
Joined: 04 May 2012
Total Posts: 269
27 Apr 2015 10:37 PM
local CreateReadOnlyTable = function(...)
local Table = {...}
local Data = newproxy(true)
getmetatable(Data).__index = Table
return Data
end


CreateReadOnlyTable(6, 1, print, "hi")
Report Abuse
JimmyChance is not online. JimmyChance
Joined: 01 Nov 2009
Total Posts: 3681
27 Apr 2015 10:38 PM
Wouldn't that be a read-only userdata (not that it matters much)?
Report Abuse
Viscoelastic is not online. Viscoelastic
Joined: 04 May 2012
Total Posts: 269
27 Apr 2015 10:40 PM
-_-
Yes, but it references a table. Using a userdata is the best method anyways.
Report Abuse
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
27 Apr 2015 10:40 PM
^
Report Abuse
NotAshley is not online. NotAshley
Joined: 16 Jan 2014
Total Posts: 14257
27 Apr 2015 10:40 PM
local tbl = setmetatable({a="I'm read only!"}, {__metatable = "Locked"})
Report Abuse
NotAshley is not online. NotAshley
Joined: 16 Jan 2014
Total Posts: 14257
27 Apr 2015 10:41 PM
I think, I could be horribly wrong
Report Abuse
Viscoelastic is not online. Viscoelastic
Joined: 04 May 2012
Total Posts: 269
27 Apr 2015 10:42 PM
You are horrible wrong. That only makes the metatable inaccessible (Which means you can't even read it)
Report Abuse
JimmyChance is not online. JimmyChance
Joined: 01 Nov 2009
Total Posts: 3681
27 Apr 2015 10:43 PM
@Visco

I agree
Report Abuse
JimmyChance is not online. JimmyChance
Joined: 01 Nov 2009
Total Posts: 3681
27 Apr 2015 10:43 PM
(to your post above)
Report Abuse
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
27 Apr 2015 10:45 PM
My arrow was actually directed at Jimmy.
Though you are right, the goal was to make a read-only table.
Report Abuse
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
27 Apr 2015 10:49 PM
This is what I did:

function readonly(t)
local proxy={}
local meta={
__index=t,
__newindex=function()error("Attempt to modify read-only table")end
}
setmetatable(proxy,meta)
return proxy
end
Report Abuse
Viscoelastic is not online. Viscoelastic
Joined: 04 May 2012
Total Posts: 269
27 Apr 2015 10:55 PM
It appears I forgot a few things:

getfenv().type = function(Value) if pcall(function() return Value["WhAt-ArE//tHe^OdDs_ThAt*SoMeOnE=aCcEsSeS+tHiS~kEy?"] end) then return "table" else return type(Value) end end
local CreateReadOnlyTable = function(...)
local Table = {["WhAt-ArE//tHe^OdDs_ThAt*SoMeOnE=aCcEsSeS+tHiS~kEy?"] = true, ...}
local Data = newproxy(true)
local Meta = getmetatable(Data)
Meta.__index = Table
Meta.__metatable = "Hai ther"
return Data
end
Report Abuse
Viscoelastic is not online. Viscoelastic
Joined: 04 May 2012
Total Posts: 269
27 Apr 2015 10:56 PM
Eternal, that doesn't work. For one, you forgot to lock the metatable just like me.
For another, watch me change your table.
rawset(EternalsReadOnlyTable, "SomeKey", "lolololol this is why you use newproxy")
Report Abuse
Viscoelastic is not online. Viscoelastic
Joined: 04 May 2012
Total Posts: 269
27 Apr 2015 10:59 PM
It still isn't the best because it doesn't prevent you from making a wrapper, but in some cases this can make the problem VERY annoying, because wrappers are just not good enough.

SomeReadOnlyTable = setmetatable({SomeKey = "lololol I just made a wrapper for your read-only table!"}, {__index = SomeReadOnlyTable})

print(SomeReadOnlyTable.SomeKey)

You can, of course, make much better wrappers than that, but you get the idea.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image