Last active
August 29, 2015 14:05
-
-
Save nonchip/d54b37701ac54beacbe2 to your computer and use it in GitHub Desktop.
YEng "live runner" (watching and reloading the script file as it's edited)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if not _init then -- nice hack to prevent us from reopening the window every time, note the globals here | |
_init=true | |
_window=Y.sdl.quickGL("liverun opengl test") | |
end | |
-- alternatively, when reopening the window, don't forget to Y.sdl.closeWindow(_window) before, or you'll get spammed with orphaned windows. | |
while true do | |
Y.sdl.pumpEvents() | |
Y.gl.ClearColor( 0, 1, 1, 1 ) -- change this color to see it updated on the fly. | |
Y.gl.Clear(Y.gl.COLOR_BUFFER_BIT) | |
Y.sdl.gL_SwapWindow(_window) | |
Y.sdl.delay(1) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random from math | |
export _init,_window | |
if not _init | |
_init=true | |
_window=Y.sdl.quickGL "strobe test" | |
Y.sdl.gL_SetSwapInterval 1 | |
with Y | |
while true | |
.sdl.pumpEvents! | |
with Y.gl | |
.ClearColor random(0,1), random(0,1), random(0,1), 1 | |
.Clear .COLOR_BUFFER_BIT | |
with Y.sdl | |
.gL_SwapWindow _window | |
.delay 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'YEng' | |
local loadfile=loadfile | |
local filepath=arg[1] | |
if filepath=="-m" then | |
loadfile=require "moonscript.base".loadfile | |
filepath=arg[2] | |
end | |
do | |
assert(type(filepath)=="string",'arg missing.\n\nUsage:\n./lj liverun.lua some_file.lua\n./lj liverun.lua -m some_file.moon\n') | |
assert(io.open(filepath,'r'),'File "'..filepath..'" can not be opened for reading.') | |
local fileage=0 | |
local function watch() | |
if lfs.attributes(filepath,'modification') ~= fileage then | |
error("reload") | |
end | |
end | |
local function cycle() | |
fileage=lfs.attributes(filepath,'modification') | |
local filefun,err=loadfile(filepath) | |
if not filefun then print(err) end | |
local ret=xpcall(function() | |
debug.sethook(watch, "count", 1) | |
filefun() | |
debug.sethook() | |
return true | |
end,function(...) | |
debug.sethook() | |
print(debug.traceback(...)) | |
return nil | |
end) | |
debug.sethook() | |
return ret | |
end | |
while not cycle() do | |
Y.sleep(0.5) | |
end | |
print("done.") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment