Code Monkey home page Code Monkey logo

uhc-js's People

Contributors

atzedijkstra avatar norm2782 avatar spockz avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

rubendg

uhc-js's Issues

Bindings for HTML5 canvas and WebGL

These two technologies are most useful when making non-HTML document based applications.

Foreign interface would enable UHC-JS to support common use cases of drawing applications.

Note that requires support for typed arrays for WebGL to be effective.

Support for: {-# LANGUAGE BangPatterns #-}

Bang Patterns were one of two most effective optimization techniques introduced by Clean research team (along with unique types), and are one that is most used in common Haskell programs besides unboxed types.

Implementing syntax support for these may greatly increase number of Cabal packages that may compile under UHC/UHC-JS.

wrapper import declaration (callback) not working in external module

The following works:

module Main where

import Language.UHC.JS.Primitives

foreign import js "wrapper"
    wrap :: IO () -> IO (JSFunPtr (IO ()))

foreign import js "window.addEventListener('load', %1)"
    onLoad :: JSFunPtr (IO ()) -> IO ()

main :: IO ()
main = do
    wrap $ do
        alert "Hello"
    >>= onLoad 

If I move wrap and onLoad to a separate module:

Wrap.hs:

module Wrap where

import Language.UHC.JS.Primitives

foreign import js "wrapper"
    wrap :: IO () -> IO (JSFunPtr (IO ()))

foreign import js "window.addEventListener('load', %1)"
    onLoad :: JSFunPtr (IO ()) -> IO ()

Main.hs:

module Main where

import Language.UHC.JS.Primitives
import Wrap

main :: IO ()
main = do
    wrap $ do
        alert "Hello"
    >>= onLoad 

I receive a JavaScript runtime error:
Uncaught TypeError: Cannot call method '__aN__' of undefined

Can't get selector example to work

I am trying to get this example to work:

https://utrechthaskellcompiler.wordpress.com/2010/10/29/a-haskell-ffi-calling-convention-for-javascript/

Here is my source file:

module Hello where

import Language.UHC.JS.Prelude
import Language.UHC.JS.Assorted
import Language.UHC.JS.W3C.HTML5

--data Document
--foreign import js "document"   document      :: IO Document
--foreign import js "%1.write()" documentWrite :: Document -> JSString -> IO ()
--foreign import js alert :: JSString -> IO ()
--
--foreign import js "%1.getElementsByName()" documentGetElementsByName :: Document -> JSString -> IO (NodeList Node)
--
--data NodeList x
--
--foreign import js "%1.length" nodeListLength :: NodeList Node -> Int
--foreign import js "%1[%2]"    nodeListItem   :: NodeList Node -> Int -> IO Node
--
--data Node
--
--foreign import js "%1.innerHTML" elementInnerHTML :: Node -> JSString
--foreign import js "%1.tagName"   elementTagName   :: Node -> JSString

main = do d <- document
          n <- documentGetElementById d (stringToJSString "myHeader")
          alert $ jsStringToString $ elementTagName n
          alert $ jsStringToString $ elementInnerHTML n

I compile using uhc --import-path=uhcjs/uhc-js/src --target=js -O,2 jsffi.hs.

Then, I add an element using echo "<div id='myHeader'>test</div>" >> jsffi.html and then I open jsffi.html. Nothing is alerted.

I tried the example without uhc-js, that did not work either. What could be the problem?

newObj not using the right constructor

I was trying to use newObj "Image" to get an HTML Image object, but the object that was created wasn't a proper Image. It was an object but it was mostly empty.

I think the problem is in primMkObj - it's doing

return new primGetCtor(nm);

I think what's happening is the new here is treating primGetCtor itself as the constructor function, and the actual constructor that primGetCtor returns is just being ignored.

I can fix it by adding parentheses:

return new (primGetCtor(nm))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.