Visitar URL original
GitHub - darkliquid/roll: A simple dice roll parsing engine · GitHub
Skip to content
darkliquidPublic

About

A simple dice roll parsing engine

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Latest commit

 

History

86 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Roll License GoDoc CI

A simple dice roll compiler and VM that (mostly) supports the Roll20 Dice Rolling Language Specification

Usage

package main

import (
    "fmt"
    "math/rand"
    "os"
    "time"

    "github.com/darkliquid/roll"
)

func main() {
    rand.Seed(time.Now().UnixNano())
    out, err := roll.Parse(os.Stdin)
    if err != nil {
        fmt.Fprintln(os.Stderr, err)
        return
    }
    fmt.Println(out)
}

Then run echo '3d6+1' | go run main.go to get some output like:

Rolled "3d6+1" and got 6, 6, 4 for a total of 17

If you want the compiled program directly, use the compile/evaluate API:

program, err := roll.CompileString("3d6+1")
if err != nil {
    panic(err)
}

result, err := roll.EvaluateProgram(program)
if err != nil {
    panic(err)
}

fmt.Println(program.String(), result.Total)

Web (GitHub Pages)

An interactive, fully client-side version runs in the browser via WebAssembly at https://darkliquid.github.io/roll/.

To build the site locally:

mise run build-wasm

This compiles cmd/wasm to docs/roll.wasm and copies Go's wasm_exec.js into docs/. The static site can then be served from docs/ with any file server, for example python3 -m http.server --directory docs.

Development

Toolchains (Go, golangci-lint, govulncheck) are pinned in mise.toml. Install them with mise install, then run the checks through mise:

mise run ci        # build, vet, lint, vulncheck and test
mise run build     # compile every package, including js/wasm
mise run lint      # golangci-lint
mise run vulncheck # govulncheck

About

A simple dice roll parsing engine

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Contributors

Languages