Posted 18 August 2013 - 06:11 AM
Hi, I just made an OS (not released) and it was all working fine, programs were running together, the graphics were all great, and then I decided to add in the normal shell as an app.
I was expecting it to work just as normal, but something really wierd is going on….
It starts up, renders everything fine, even term.setCursorBlink works, but when I try and run a program it just freezes and doesn't appear to run the program. It doesn't error, nothing wrong with the rendering, and the coroutine status is "suspended" which I guess just means its fine but not currently running. I really have no idea how to fix the problem.
The main part that loads functions into runnable apps:
The part that runs the coroutines/apps:
The window API that does all the rendering of programs and holds the screen data (watch out, this is a fairly long one):
Oh and by the way, I am 99% sure it isn't the rendering that is the issue because I copied and pasted the Hello World program into an app and ran it and everything was fine, but running it through the shell through an app didn't work.
If anyone has an idea of whats going on, or can figure it out from the code above, that would be great!
Thanks!
Edit: Can't believe I missed this…it isn't capturing key events such as enter and backspace…*facepalm" which I guess would explain why it isn't running the program (it can't tell when you press enter). Sorry for the post :(/> This will probably be easy to fix…
Edit2: Missed out some brackets causing it to think that if it was either not on the program or got a key event it shouldn't run the program…this is embarrasing…everything is fixed
I was expecting it to work just as normal, but something really wierd is going on….
It starts up, renders everything fine, even term.setCursorBlink works, but when I try and run a program it just freezes and doesn't appear to run the program. It doesn't error, nothing wrong with the rendering, and the coroutine status is "suspended" which I guess just means its fine but not currently running. I really have no idea how to fix the problem.
The main part that loads functions into runnable apps:
Spoiler
newWindow = function( func, name )
local t = { }
for i = 1,#flutter.apps do
if flutter.apps[i].name == name then
t.func = flutter.apps[i].code
t.desc = flutter.apps[i].desc
t.image = flutter.apps[i].image
break
else
t.desc = "This program has no description associated with it"
t.func = func
end
end
t.name = name
t.env = { }
setmetatable( t.env, { __index = getfenv( ) } )
setfenv( t.func, t.env )
t.co = coroutine.create( t.func )
t.window = flutter.apis.window.newWindow( )
t.active = false
t.toggle = function( )
t.active = not t.active
if t.active then
t.window.draw( )
t.window.drawToReal = true
else
t.window.drawToReal = false
end
end
t.activate = function( )
if not t.active then
t.toggle( )
end
end
t.deactivate = function( )
if t.active then
t.toggle( )
end
end
t.run = function( ... )
if coroutine.status( t.co ) ~= "dead" then
term.redirect( t.window.functions )
local ok, err = coroutine.resume( t.co, ... )
term.restore( )
if not ok then
t.desc = "Program error:\n"..err
end
end
end
return t
end
Spoiler
for i = 1,#flutter.programs-1 do
if not ( ev[1] == "mouse_click" or ev[1] == "mouse_drag" or ev[1] == "mouse_scroll" or ev[1] == "key" or ev[1] == "char" ) then
flutter.programs[i].run( unpack( ev ) )
end
end
if #flutter.programs > 0 then
flutter.programs[#flutter.programs].run( unpack( ev ) )
end
Spoiler
local oldterm = { }
for k, v in pairs( term ) do
oldterm[k] = v
end
local createBlank = function( w, h )
local t = { }
for y = 1,h do
t[y] = { }
for x = 1,w do
t[y][x] = { bc = 32768, tc = 1, char = " " }
end
end
return t
end
newWindow = function( )
local t = { }
t.drawToReal = false
t.screen = createBlank( term.getSize( ) )
t.data = {
x = 1;
y = 1;
bc = 32768;
tc = 1;
cb = false;
}
t.functions = { }
t.functions.pixel = function( x, y, bc, tc, char, nr )
if t.screen[y] and t.screen[y][x] then
t.screen[y][x] = { bc = bc or t.screen[y][x].bc, tc = tc or t.screen[y][x].tc, char = char or t.screen[y][x].char }
if t.drawToReal then
term.restore( )
term.setCursorPos( x, y )
term.setBackgroundColour( t.screen[y][x].bc )
term.setTextColour( t.screen[y][x].tc )
term.write( t.screen[y][x].char )
if not nr then
term.redirect( t.functions )
end
end
end
end;
t.functions.write = function( text )
for i = 1,text:len( ) do
t.functions.pixel( t.data.x, t.data.y, t.data.bc, t.data.tc, text:sub( i, i ) )
t.data.x = t.data.x + 1
if t.data.x > #t.screen[1] then
break
end
end
end;
t.functions.clearLine = function( n )
for i = 1,#t.screen[n] do
t.functions.pixel( i, n, t.data.bc, t.data.tc, " " )
end
end;
t.functions.clear = function( )
for i = 1,#t.screen do
t.functions.clearLine( i )
end
end;
t.functions.setBackgroundColour = function( col )
t.data.bc = col
end;
t.functions.setTextColour = function( col )
t.data.tc = col
end;
t.functions.setBackgroundColor = function( col )
t.data.bc = col
end;
t.functions.setTextColor = function( col )
t.data.tc = col
end;
t.functions.setCursorPos = function( x, y )
t.data.x, t.data.y = x, y
end;
t.functions.getCursorPos = function( )
return t.data.x, t.data.y
end;
t.functions.scroll = function( n )
local newLine = { }
for i = 1,#t.screen[1] do
newLine[i] = { bc = t.data.bc, tc = t.data.tc, char = " " }
end
for i = 1,math.abs( n ) do
if n < 0 then
table.insert( t.screen, 1, newLine )
table.remove( t.screen, #t.screen )
else
table.insert( t.screen, newLine )
table.remove( t.screen, 1 )
end
end
end;
t.functions.getSize = function( )
return #t.screen[1], #t.screen
end;
t.functions.isColour = function( ) return true end;
t.functions.isColor = function( ) return true end;
t.functions.setCursorBlink = function( tof, nr )
t.data.cb = not not tof
if t.drawToReal then
term.restore( )
term.setCursorBlink( t.data.cb )
if not nr then
term.redirect( t.functions )
end
end
end;
t.draw = function( )
for y = 1,#t.screen do
for x = 1,#t.screen[y] do
term.setCursorPos( x, y )
term.setBackgroundColour( t.screen[y][x].bc )
term.setTextColour( t.screen[y][x].tc )
term.write( t.screen[y][x].char )
end
end
end
return t
end
Oh and by the way, I am 99% sure it isn't the rendering that is the issue because I copied and pasted the Hello World program into an app and ran it and everything was fine, but running it through the shell through an app didn't work.
If anyone has an idea of whats going on, or can figure it out from the code above, that would be great!
Thanks!
Edit: Can't believe I missed this…it isn't capturing key events such as enter and backspace…*facepalm" which I guess would explain why it isn't running the program (it can't tell when you press enter). Sorry for the post :(/> This will probably be easy to fix…
Edit2: Missed out some brackets causing it to think that if it was either not on the program or got a key event it shouldn't run the program…this is embarrasing…everything is fixed