]> granicus.if.org Git - nethack/commitdiff
add build section, fix naming
authorAdam Powers <apowers@ato.ms>
Sun, 30 Aug 2020 17:45:54 +0000 (10:45 -0700)
committerAdam Powers <apowers@ato.ms>
Sun, 30 Aug 2020 17:45:54 +0000 (10:45 -0700)
sys/lib/README.md

index d27a3e8752b9a7091817b4e11a75918ae0d8084f..cbbd87b5152fd955370f679de5d3ab39e0eb4cb9 100644 (file)
@@ -3,12 +3,27 @@ This creates a library for NetHack that can be incorporated into other programs.
 * libnethack.a - a binary Unix library
 * nethack.js / nethack.wasm - a [WebAssembly / WASM](https://webassembly.org/) library for use in JavaScript programs (both nodejs and browser)
 
-## API: libnethack.a
-This libarary has only been built on MacOS, but should work on Linux and other unix-ish platforms. If you have problems, start by stealing hints files from the `sys/unix/hints` for your platform. Contributions for other platforms are happily accepted.
+## Build
+This library has only been built on MacOS, but should work on Linux and other unix-ish platforms. If you have problems, start by stealing hints files from the `sys/unix/hints` for your platform. Contributions for other platforms are happily accepted.
+
+Building the WASM module requires that you have the [emscripten toolchain / sdk installed](https://emscripten.org/docs/getting_started/downloads.html).
+
+Generally the build is the same as the unix build:
+1. `cd sys/lib`
+2. For `libnethack.a`: `./setup.sh hints/macOS.2020`; for `nethack.js`: `./setup.sh hints/wasm`
+3. `cd ../..`
+4. `make`
+
+Resulting libaries will be in the `src` directory.
 
+WASM also has a npm module that can be published out of `sys/lib/npm-library`. After building the `nethack.js` it can be published by:
+1. `cd sys/lib/npm-library`
+2. `npm publish`
+
+## API: libnethack.a
 The API is two functions:
 * `nhmain(int argc, char *argv[])` - The main function for NetHack that configures the program and runs the `moveloop()` until the game is over. The arguments to this function are the [command line arguments](https://nethackwiki.com/wiki/Options) to NetHack.
-* `stub_graphics_set_callback(stub_callback_t cb)` - A single function that sets a callback to gather graphics events: write a string to screen, get user input, etc. Your job is to pass in a callback and handle all the requested rendering events to show NetHack on the scrren. The callback is `void stub_callback_t(const char *name, void *ret_ptr, const char *fmt,  ...)`
+* `shim_graphics_set_callback(shim_callback_t cb)` - A single function that sets a callback to gather graphics events: write a string to screen, get user input, etc. Your job is to pass in a callback and handle all the requested rendering events to show NetHack on the scrren. The callback is `void shim_callback_t(const char *name, void *ret_ptr, const char *fmt,  ...)`
   * `name` is the name of the [window function](https://github.com/NetHack/NetHack/blob/NetHack-3.7/doc/window.doc) that needs to be handled
   * `ret_ptr` is a pointer to a memory space for the return value. The type expected to be returned in this pointer is described by the first character of the `fmt` string.
   * `fmt` is a string that describes the signature of the callback. The first character in the string is the return type and any additional characters describe the variable arguments: `i` for integer, `s` for string, `p` for pointer, `c` for character, `v` for void. For example, if format is "vis" the callback will have no return (void), the first argument will be an integer, and the second argument will be a string. If format is "iii" the callback must return an integer, and both the arguments passed in will be integers.
@@ -17,11 +32,9 @@ The API is two functions:
 Where is the header file for the API you ask? There isn't one. It's three functions, just drop the forward declarations at the top of your file (or create your own header). It's more work figuring out how to install and copy around header files than it's worth for such a small API. If you disagree, feel free to sumbit a PR to fix it. :)
 
 ## API: nethack.js
-Building the WASM module requires that you have the [emscripten toolchain / sdk installed](https://emscripten.org/docs/getting_started/downloads.html).
-
 The WebAssembly API has a similar signature to `libnethack.a` with minor syntactic differences:
 * `main(int argc, char argv[])` - The main function for NetHack
-* `stub_graphics_set_callback(stub_callback_t cb)` - The same as above, but the signature of the callback is slightly different because WASM can't handle variadic callbacks. The callback is: `void stub_callback_t(const char *name, void *ret_ptr, const char *fmt,  void *args[])`
+* `shim_graphics_set_callback(shim_callback_t cb)` - The same as above, but the signature of the callback is slightly different because WASM can't handle variadic callbacks. The callback is: `void shim_callback_t(const char *name, void *ret_ptr, const char *fmt,  void *args[])`
   * `name` - same as above
   * `ret_ptr` - same as above
   * `fmt` - same as above
@@ -30,22 +43,22 @@ The WebAssembly API has a similar signature to `libnethack.a` with minor syntact
 
 
 ## API Stability
-The "stub graphics" API should generally be stable. I aspire to replace the command line arguments (argc / argv) with a structure of options, so the `nhmain()` and `main()` functions may change at some point.
+The "shim graphics" API should generally be stable. I aspire to replace the command line arguments (argc / argv) with a structure of options, so the `nhmain()` and `main()` functions may change at some point.
 
 ## libnethack.a example
 ``` c
 #include <stdio.h>
 
 int nhmain(int argc, char *argv[]);
-typedef void(*stub_callback_t)(const char *name, void *ret_ptr, const char *fmt, ...);
-void stub_graphics_set_callback(stub_callback_t cb);
+typedef void(*shim_callback_t)(const char *name, void *ret_ptr, const char *fmt, ...);
+void shim_graphics_set_callback(shim_callback_t cb);
 
 void window_cb(const char *name, void *ret_ptr, const char *fmt, ...) {
     /* TODO -- see windowCallback below for hints */
 }
 
 int main(int argc, char *argv[]) {
-    stub_graphics_set_callback(window_cb);
+    shim_graphics_set_callback(window_cb);
     nhmain(argc, argv);
 }
 ```
@@ -76,7 +89,7 @@ function setGraphicsCallback() {
 
     console.log("setting callback function with library");
     Module.ccall(
-        "stub_graphics_set_callback", // C function name
+        "shim_graphics_set_callback", // C function name
         null, // return type
         ["number"], // arg types
         [cb], // arg values