npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

glk

v1.0.0

Published

Glk protocol for JavaScript

Downloads

14

Readme

This is a library to use Glk from JavaScript code. This program is public
domain, although dispatch.js contains Glk dispatch data which comes from
a program with MIT license, so the dispatch.js file has its own copyright
notice in order to acknowledge this.

It also includes a protocol for encoding Glk dispatches as byte streams,
and internally uses it; you need not touch it directly, though.

Before using it, you may need to modify the startup code and compiling
instructions in glkrun.c for use with the Glk implementation you use. The
present implementation is for GlkTerm.

This module exports an object with property names being all of the Glk
constants and Glk functions, without "glk_" at front. The values of the
constants are numbers. The functions are callable JavaScript functions.

The following describes corresponding Glk types with JavaScript types:

* Integers (glui32, glsi32): A JavaScript number.

* Character (char, signed char, unsigned char): A JavaScript number.

* String of 8-bit characters: A JavaScript string. Must consist only of
codepoints in range 1 to 255.

* String of 32-bit characters: A JavaScript string. Must be valid UTF-16
with no null characters; will internally be converted into UTF-32.

* Opaque objects: These are represented as a JavaScript object, or null
if there is no object (only valid for some functions). The object will be
an object of one of the four classes mentioned below, although they have
no properties, except those inherited from Object, and a new version of
the toString function for debugging purposes. It must be an object that
is returned by a Glk function and has not yet been destroyed; otherwise
it will throw an error (if you create your own objects in JavaScript, even
if they have the correct classes, they will also throw an error).

* Structures: Use a JavaScript array, containing the values in order. If
the Glk function only writes to it and does not read it, you can omit the
values and it will still work.

* Arrays: It must be either a Array, Uint8Array, Int8Array, Uint32Array,
or Int32Array; depending on the type of the data, some types might not be
allowed. There is no length argument; it is implied. Sometimes arrays are
retained by Glk; in this case, the array will be written to once it is no
longer retained, and you may read back the data at that time (for example,
this is needed to handle line input events).

* References: Some Glk functions use references passed in and/or out. In
this case, scalar values need to be wrapped in a JavaScript array with a
single element; if passed out only, then it can be initially empty. If a
reference is allowed to be omitted, you may pass null to omit it.

Other properties of the exported object include:

.Channel()
  The class of Glk sound channels.

.File()
  The class of Glk filerefs.

.Stream()
  The class of Glk streams.

.Window()
  The class of Glk windows.

._classes
  Used internally to create JavaScript objects for opaque references.

._dispatch(id,proto)
  The first argument is a 16-bit Glk function number. The second argument
  is a string in the format described by section 12.1.4 ("Getting Argument
  Prototypes") of the Glk specification. This function returns another
  function, which can be called to call the Glk function. Normally there
  is no need to call _dispatch() directly, although you might use it if
  you need to call extension functions. If id is 1 then calling the
  returned function will terminate the process after sending the dispatch
  call; this is a special case.

._read(buf)
  Receive the buffer from Glk; the entire contents of the buffer is
  overwritten. Used internally; you should not use this yourself,
  although you may override it if needed.

._read1(buf)
  Receive one byte from Glk, and store it in the first cell of the buffer.
  Used internally; you should not use this yourself, although you may
  override it if needed.

._write(buf)
  Send the buffer to Glk. Used internally; you should not use this
  yourself, although you may override it if needed.

.bufToString(buf,len)
  The first argument needs to be a Uint32Array or Uint8Array. The second
  argument is the length of the data. You can use this when requesting
  line events in order to get the data back.