Skip to main content

Waggle 🐝 — a scripting language with Discord, game, JS interop and more

Project description

Waggle 🐝 v2.0.0

Named after the waggle dance — how bees communicate the exact location of something valuable.

Waggle é uma linguagem de script experimental com sintaxe limpa, inspirada em Python.
Arquivos usam a extensão .wg.


Instalação

python -m pip install .

Extras opcionais:

python -m pip install ".[discord]"
python -m pip install ".[game3d]"

CLI

waggle run script.wg       # executa um arquivo
waggle install requests     # instala pacote Python
waggle new meu_projeto      # scaffold de projeto
waggle version              # versão

Atalho direto:

waggle script.wg

Funcionalidades

Variáveis

x = 10
let PI = 3.14   # constante

F-strings

nome = "Abelha"
print(f"Olá, {nome}! 2+2={2+2}")

Tipos nativos e métodos

Listas:

nums = [1, 2, 3]
nums.push(4)
print(nums.len())         # 4
print(nums.contains(2))   # true
print(nums.join(", "))    # 1, 2, 3, 4
nums.sort()
print(nums.first())       # 1

Strings:

s = "  waggle  "
print(s.trim())           # "waggle"
print(s.upper())          # "  WAGGLE  "
print(s.split(" "))       # lista de partes
print(s.contains("wag")) # true

Maps:

cfg = {host: "localhost", port: 8080}
print(cfg.keys())
cfg.set("debug", true)
print(cfg.has("debug"))   # true

try / catch / throw

try:
    throw "algo deu errado"
catch e:
    print(f"Capturado: {e}")

match / case

x = 2
match x:
    case 1:
        print("um")
    case 2:
        print("dois")
    default:
        print("outro")

Subscript

arr = [10, 20, 30]
print(arr[1])    # 20
arr[0] = 99
print(arr[0])    # 99

Potência

print(2 ** 10)   # 1024

pyimport / frompy (Python)

pyimport math
print(math.sqrt(16))

frompy os.path import join
print(join("a", "b"))

jsimport / fromjs (Node.js)

Requer Node.js instalado.

utils.js:

module.exports = { PI: 3.14159, appName: "Waggle" }

script.wg:

jsimport utils
print(utils.PI)

fromjs utils import appName
print(appName)

jsrun — JS inline

resultado = jsrun("return 2 ** 16")
print(resultado)   # 65536

discord (interno)

import discord

let bot = discord.bot("TOKEN", "!")

fn on_ready():
    printc("Bot online!", "honey")

fn on_message(msg):
    if msg.content == "!ping":
        msg.reply("🐝 pong!")

Builtins novos

Função Descrição
type(x) tipo como string
abs(x) valor absoluto
min/max(...) mínimo/máximo
round(x, n) arredonda
floor/ceil(x) piso/teto
sqrt(x) raiz quadrada
pow(b, e) potência
map(fn, lst) aplica função à lista
filter(fn, lst) filtra lista
reduce(fn, lst) reduz lista
sorted(lst) cópia ordenada
zip(a, b) zipa duas listas
enumerate(lst) índice + valor
flat(lst) achata lista
json_encode(x) serializa JSON
json_decode(s) desserializa JSON
sleep(s) pausa em segundos
assert(cond, msg) asserção
jsrun(code) executa JS inline
error(msg) lança erro
color(txt, cor) texto colorido (ANSI)
printc(txt, cor) imprime colorido

Cores extras exclusivas: honey, hive, pollen 🐝


Licença

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

waggle_lang-2.0.0.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

waggle_lang-2.0.0-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

Details for the file waggle_lang-2.0.0.tar.gz.

File metadata

  • Download URL: waggle_lang-2.0.0.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for waggle_lang-2.0.0.tar.gz
Algorithm Hash digest
SHA256 0ae52ac121e2a35ce5536ff72e3e2a4bf40bb3b8815b0c6a0cea7b0cac9b209f
MD5 0d9d23d8a2a53613b18884474de6b841
BLAKE2b-256 9538a9c446576932728a44fce93675f6198526e1c581c1c8345c85fa408ae5dc

See more details on using hashes here.

File details

Details for the file waggle_lang-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: waggle_lang-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 21.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for waggle_lang-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c4e66b842767a8427266209b95b1f187e8d285a36254f317c5e84d7f72e37b74
MD5 d46167d80c430f27d0c6ad37acadcec6
BLAKE2b-256 1cb4f297274acca535fc892ae76ecbc9e1a0ff20bc065db6e391406000fedbc4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page