Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ How do we tell if a function is sandboxed?
How do we tell if a function is sandboxed?
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Shaun Biggs
USA (644 posts) Bio
|
Date
| Wed 17 Jun 2009 05:35 AM (UTC) |
Message
| So I was trying to make a bit of a debugging log for a plugin of mine which has had issues running on a clanmate's computer. While testing, I forgot that io.open() was sandboxed. Is there any way to have a script check to see if a function is sandboxed before attempting to access the function? I would much rather check before having a bunch of errors pop up on the screen.
The functions are actually different:
print( io.open )
print( io.write )
print( io.read )
function: 00DE55F8
function: 00DE5490
function: 00DE6060
Would it be possible to have a sandboxed() function which the other functions could reference if they are sandboxed, rather than having a new function created each time doing the same exact thing?
a = function() end
b = a
print( a.."\n"..b )
function: 013A84A0
function: 013A84A0
This way we can check if a function is sandboxed with a quick comparison, or a world.sandboxed( foo ) function returning true/false. I'm hoping this exists already, and I just do not know of it yet. |
It is much easier to fight for one's ideals than to live up to them. | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #1 on Wed 17 Jun 2009 06:47 AM (UTC) Amended on Wed 17 Jun 2009 06:48 AM (UTC) by Nick Gammon
|
Message
| If io.open is sandboxed, it will be a Lua function. If not, it will be a C function.
For example, if not sandboxed:
/tprint (debug.getinfo (io.open, "S"))
"source"="=[C]"
"what"="C"
"lastlinedefined"=-1
"linedefined"=-1
"short_src"="[C]"
If sandboxed:
/tprint (debug.getinfo (io.open, "S"))
"source"="Sandbox"
"what"="Lua"
"lastlinedefined"=42
"linedefined"=38
"short_src"="[string "Sandbox"]"
As you can see, most (er, all) of the debug info is different if it is sandboxed. So something like this could be used:
if debug.getinfo (io.open, "S").source == "Sandbox" then
print ("warning, io.open sandboxed")
end -- if
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Shaun Biggs
USA (644 posts) Bio
|
Date
| Reply #2 on Wed 17 Jun 2009 09:40 AM (UTC) |
Message
| Thank you very much. That makes what I am doing much easier. I am can now check to see if I can deal with logging some debugging information with a quick check. Just in case anyone else will find it useful:
loggable = true
for _,v in pairs( io ) do
if type(v) == "function" then
if debug.getinfo (v, "S").source == "Sandbox" then
loggable = false
end -- if sandboxed
end -- check only functions
end
|
It is much easier to fight for one's ideals than to live up to them. | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
12,580 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top