This file contains 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
type JSString = PackedString | |
foreign import prim "primStringToPackedString" toJS :: String -> JSString | |
data Document | |
foreign import js "document" getDocument :: IO Document | |
foreign import js "%1.write(%2)" write :: Document -> JSString -> IO () | |
main = do | |
doc <- getDocument | |
write doc $ toJS "Hello, World!" |
This file contains 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
function objWrite(obj, text, _realWorld) { | |
obj.write(text); // Call the method | |
return [1,0]; // Return () | |
} | |
function getDocument(_realWorld) { | |
return [1, 0, document]; | |
} |
This file contains 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 Haste | |
import Haste.Prim | |
type Document = JSAny | |
foreign import ccall "objWrite" write :: Document -> JSString -> IO () | |
foreign import ccall "getDocument" getDocument :: IO Document | |
main = do | |
doc <- getDocument |
This file contains 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
<!DOCTYPE html><html><head><title>Main</title> | |
<script type="text/javascript" src="Main.js"></script> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains 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
function jsSetInterval(msecs, cb, _) { | |
window.setInterval(function() {A(cb,[0]);}, msecs); | |
return [1,0]; | |
} | |
function jsSetOnKeyDown(cb, _) { | |
window.addEventListener('keydown', function(e) {A(cb,[[1,parseInt(e.keyCode)],0]);}, true); | |
return [1,0]; | |
} |
This file contains 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 UHC.Ptr | |
foreign import js "wrapper" mkCb :: IO () -> IO (FunPtr (IO ()) |
This file contains 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
data JSKeyEvent | |
foreign import js "wrapper" | |
mkKeyEventCb :: (JSKeyEvent -> IO ()) -> IO (FunPtr (JSKeyEvent -> IO ())) |
This file contains 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
foreign import js "%1.keyCode" | |
keyCode :: JSKeyEvent -> IO Int | |
foreign import js "window.addEventListener('keydown',%1,true)" | |
jsSetOnKeyDown :: FunPtr (JSKeyEvent -> IO ()) -> IO () | |
setOnKeyDown (Int -> IO ()) -> IO () | |
setOnKeyDown fp = dp | |
cb <- mkKeyEventCb fp' | |
jsSetOnKeyDown cb |
This file contains 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
foreign import ccall jsSetInterval :: Int -> Callback a -> IO () | |
setInterval :: Int -> IO () -> IO () | |
setInterval time cb = | |
jsSetInterval time (mkCallback $! cb) | |
foreign import ccall jsSetOnKeyDown :: Callback a -> IO () | |
foreign import ccall jsSetOnKeyUp :: Callback a -> IO () | |
setOnKeyDown :: (Int -> IO ()) -> IO () | |
setOnKeyDown cb = |
This file contains 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
var allObjects = {} | |
function saveObject(name, obj) { | |
allObjects[name] = obj; | |
} | |
function loadObject(name) { | |
return allObjects[name]; | |
} |
OlderNewer