- ComputerCraft | Programmable Computers for Minecraft
- → cntkillme's Content
cntkillme's Content
There have been 24 items by cntkillme (Search limited from 10-February 22)
#267179 fs.open/io.open creating files in root directory?
Posted by
cntkillme
on 22 May 2017 - 05:01 AM
in
Ask a Pro
I know I can use shell.resolve to solve this but why isn't this implicit?
Edit this seems to happen with every function that expects a path (i.e. os.run, etc.)
#267154 Running 2 programs within the same shell on 2 different windows?
Posted by
cntkillme
on 21 May 2017 - 05:19 AM
in
Ask a Pro
Heh, I'll just use lyqydos and not reinvent the wheel since it's already been done and better. Sure it's slightly different than what I want but it's far more flexible.
#267149 Running 2 programs within the same shell on 2 different windows?
Posted by
cntkillme
on 21 May 2017 - 12:07 AM
in
Ask a Pro
Still have to handle certain things like the mouse_click events and such to make sure they only fire for windows they're in but that'll be a piece of cake.
Hmm. I'm reinventing the wheel. There's probably a better "windows" API that handles this for me. Anyways:
https://puu.sh/vWx6J/80685016ed.mp4
#267128 Running 2 programs within the same shell on 2 different windows?
Posted by
cntkillme
on 20 May 2017 - 11:05 AM
in
Ask a Pro
local _term = term
_G.term = setmetatable({ }, {
__index = function(_, key)
local env
_, env = pcall(getfenv, 4) -- i dont know how reliable this is going to be
if _ then
if env == envA then
return termA[key]
elseif env == envB then
return termB[key]
end
end
return _term[key]
end})
#267127 Running 2 programs within the same shell on 2 different windows?
Posted by
cntkillme
on 20 May 2017 - 10:44 AM
in
Ask a Pro
So my first approach was to do:
local sX, sY = term.getSize()
local fileA, fileB = "blah", "blah blah"
local termA = window.create(term.current(), 1, 1, sX, sY/2)
local termB = window.create(term.current(), 1, sY/2+1, sX, sY/2)
parallel.waitForAny(
function() os.run({ term = termA }, fileA) end,
function() os.run({ term = termB }, fileB) end
)
However this fails to work unless all outputting I do is through term (for example when I call print). I then tried to wrap term.current and force it to return termA if the first script called it and termB if the second one did:
local envA = { term = termA }
local envB = { term = termB }
local _current = term.current
function term.current()
local env = getfenv(2)
if env == envA then
return termA
elseif env == envB then
return termB
else
return _current()
end
end
But that didn't work. Is there a way to do what I want? I don't know much about the CC API so if this is obvious I'm sorry
#267122 Creating Userdata?
Posted by
cntkillme
on 20 May 2017 - 05:37 AM
in
Ask a Pro
#267111 Avoiding common bad practices in your code
Posted by
cntkillme
on 19 May 2017 - 07:48 PM
in
Tutorials
And all functions in Lua are closures regardless if they have any upvalues. All a closure is, though, is a pointer to a function prototype (contains static info. like constants, instructions, and nested prototypes), its upvalues, and its environment.
#267093 require function
Posted by
cntkillme
on 19 May 2017 - 02:32 AM
in
Suggestions
#267091 require function
Posted by
cntkillme
on 19 May 2017 - 02:06 AM
in
Suggestions
os.loadAPI clutters the global environment and forces the name of the API to be the file name.
dofile requires the script to be recompiled every time.
os.run is just not a good solution either.
Why doesn't require exist? I mean sure it's easy to implement on our own but having it be an actual feature makes it so we don't have to create a startup script for each computer just to do it.
I understand there is overhead but again if the package table can be accessed we can free libraries we no longer need to use.
#267090 Creating Userdata?
Posted by
cntkillme
on 19 May 2017 - 12:49 AM
in
Ask a Pro
Anyways, the problem with not closing it is that the file will stay open until the computer is rebooted/shutdown. Although yeah I mean my solution currently is to wrap os.pullEvent and os.pullEventRaw to accept a callback function that is called if the signal was terminate.
Seems like a clean way to do it, no?
#267087 Creating Userdata?
Posted by
cntkillme
on 19 May 2017 - 12:00 AM
in
Ask a Pro
I might just end up not using rednet.receive if last comes to last but I'm curious to if there is a way to do this more nicely. I don't really understand why `newproxy` was removed since it'd be perfect in this scenario.
I was thinking I might be able to set the metatable of the file object returned to have __gc but io.open and fs.open return tables so that's also a no go.
Edit: Nope never mind they don't share the same env. although they fallback to the same table with the built-ins. If I call rednet.receive after writing over os.pullEventRaw, wouldn't it change all script in that case. Although this could be a good thing, I can have it take an optional "onTerminate" function.
#267072 Creating Userdata?
Posted by
cntkillme
on 17 May 2017 - 08:42 PM
in
Ask a Pro
The reason I need this is that in the case the script is terminated or it errors or something I want to ensure I clean up everything correctly. The reason is that for my Logger class it only opens the file once and stores the handle. The problem though is since tables don't fire the __gc metamethod in 5.1 I cannot guarantee this file is closed.
My original solution was to return an object created from newproxy and the __gc metamethod would be fired in the case that went out of scope.
I know I could use os.pullEventRaw and handle it when the script is terminated but then that prevents me from using rednet.receive which is a wrapper function I really like. Also it doesn't entirely handle the case when the logger object goes out of scope (although I can ensure that won't happen I guess).
Is there another way to do what I need?
#267066 [MC 1.8.9-1.11.2] CC Tweaks
Posted by
cntkillme
on 17 May 2017 - 06:54 AM
in
Peripherals and Turtle Upgrades
Is this facading mod I'm using just bad and if so do you know of any for 1.8.9 as I can't find any working ones.
#267043 Is there a way I can get the label of a computer connected to a network?
Posted by
cntkillme
on 15 May 2017 - 06:47 AM
in
Ask a Pro
I know I can get a handle to it using peripheral.wrap but I don't think I can get the label from there.
My current solution is to have one computer just ask the other computer what its label is.
Also, another unrelated question: I read that if you label your computer, destroy it, recreate one, and set the label to what it was previously all the data would be saved. Is there a way to disable this since it sort of ruins multiplayer for me?
- ComputerCraft | Programmable Computers for Minecraft
- → cntkillme's Content


