Added js console object
This commit is contained in:
parent
723bc158ce
commit
693b2b0f5d
2 changed files with 41 additions and 0 deletions
32
lib/js/jsconsole.nim
Normal file
32
lib/js/jsconsole.nim
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#
|
||||
#
|
||||
# Nim's Runtime Library
|
||||
# (c) Copyright 2012 Andreas Rumpf
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
#
|
||||
|
||||
## Wrapper for the `console` object for the `JavaScript backend
|
||||
## <backends.html#the-javascript-target>`_.
|
||||
|
||||
when not defined(js) and not defined(Nimdoc):
|
||||
{.error: "This module only works on the JavaScript platform".}
|
||||
|
||||
type Console* {.importc.} = ref object of RootObj
|
||||
|
||||
{.push importcpp .}
|
||||
|
||||
proc log*[A](console: Console, a: A)
|
||||
proc debug*[A](console: Console, a: A)
|
||||
proc info*[A](console: Console, a: A)
|
||||
proc error*[A](console: Console, a: A)
|
||||
|
||||
{.pop.}
|
||||
|
||||
proc log*(console: Console, a: string) = console.log(cstring(a))
|
||||
proc debug*(console: Console, a: string) = console.log(cstring(a))
|
||||
proc info*(console: Console, a: string) = console.log(cstring(a))
|
||||
proc error*(console: Console, a: string) = console.log(cstring(a))
|
||||
|
||||
var console* {.importc, nodecl.}: Console
|
||||
9
tests/js/tconsole.nim
Normal file
9
tests/js/tconsole.nim
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
discard """
|
||||
output: "Hello, console"
|
||||
"""
|
||||
|
||||
# This file tests the JavaScript console
|
||||
|
||||
import jsconsole
|
||||
|
||||
console.log("Hello, console")
|
||||
Loading…
Add table
Add a link
Reference in a new issue