This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Trip's profile picture

[Lua] Own "wrap"

Started by Trip, 19 September 2012 - 01:56 PM
Trip #1
Posted 19 September 2012 - 03:56 PM
Hi,

I want to have own "wrapped" functions, like I do with peripheral.wrap(). Can you please give me any link to documentation or anything? I really don't know what to search, so I had to write this.

Thanks a lot,

Trip.
GopherAtl #2
Posted 19 September 2012 - 04:14 PM
Wrap isnt magic, it just returns a table containing functions. I'm assuming you want to make something you can redirect term to, in which case you just make a table, write your versions of getCursorPos, setCursorPos, write, etc. and set them into a table, like this…


--can define funcs outside...
function myWrite(text)
  --code here
end

--or in the table itself
local myTermWrap={
  setCursorPos=function(text) <code> end,
  write=myWrite,
  etc.
}
I just showed two to demonstrate, you have to do 7 for a proper redirect - set/getCursorPos, getSize, clear, clearLine, write, and setCursorBlink.
Trip #3
Posted 19 September 2012 - 04:16 PM
Nice, this is what I wanted. Thanks! :)/>/>
Lyqyd #4
Posted 20 September 2012 - 06:30 AM
Wrap isnt magic, it just returns a table containing functions. I'm assuming you want to make something you can redirect term to, in which case you just make a table, write your versions of getCursorPos, setCursorPos, write, etc. and set them into a table, like this…


--can define funcs outside...
function myWrite(text)
  --code here
end

--or in the table itself
local myTermWrap={
  setCursorPos=function(text) <code> end,
  write=myWrite,
  etc.
}
I just showed two to demonstrate, you have to do 7 for a proper redirect - set/getCursorPos, getSize, clear, clearLine, write, and setCursorBlink.

Oh? Is scroll not required?
GopherAtl #5
Posted 20 September 2012 - 01:32 PM
oops, no, scroll is definitely required, I just forgot to list it!