Jump to content




Problem with "sandboxing"/logging program


  • You cannot reply to this topic
4 replies to this topic

#1 Kouksi44

  • Members
  • 89 posts
  • LocationMunich, Germany

Posted 10 December 2014 - 07:00 PM

Hey everybody !

I was bored and decided to make some kind of program that runs a program and logs most of the things it does.

Well, turned out that it is not that easy...

Currently I am really not that far in my code so... This is it (probably terrible wrong ^^) Or atleast the relevant parts:

setmetatable(mt,{__index=function(t,k) logger.writeLine("program tried to access undefined value at key"..k.." in  table "..t) logger.flush() return _G.t[k] end, __newindex=function(t,k,v) logger.writeLine("Program tried to create new value at "..k.."  with value"..v.."  in table "..t) logger.flush()  end})
setfenv(content, mt)
content()

Right now, I am always getting an error when trying to write something to my logger file. It gives me an "attempt to concatenate string an function/table whatever".

Im pretty sure its because I am trying to write k or v or so in the file without converting it into the right format.

However I have absolutely no idea how to fix this ?

It would be pretty awesome if someone could help me :)

mfG Kouksi44

#2 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 10 December 2014 - 07:38 PM

What is happening is you are trying to concatenate t (which is a table) and your string ("program tried to access undefined value at key"). Wrapping t in a tostring() call should solve the problem:
Spoiler

__index takes the current table and the key
__newindex takes the current table, the key and the value.

So the first parameter will always be a table.

#3 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 10 December 2014 - 07:45 PM

What is the point of printing the table? It'll just spit out some random stuff (eg. "table: 0x547578" )

#4 Kouksi44

  • Members
  • 89 posts
  • LocationMunich, Germany

Posted 10 December 2014 - 08:54 PM

Ah okay thank you ! :)
I'l have a look tomorrow !

Well the code above is not really useful I just wanted to see how this works and what I can do with it :)

#5 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 10 December 2014 - 09:10 PM

Edit: Whoops, seems I had this tab open for a couple of hours. Go me.

Edited by Bomb Bloke, 10 December 2014 - 09:11 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users