Giter VIP home page Giter VIP logo

nim-webgl-example's Introduction

A Nim/WebGL example, using dts2nim

This is a demo of how to use the dts2nim tool to create a hybrid Nim/TypeScript web app.

Running

You will need Typescript, npm and nim installed and available from your command line. You can get Typescript from npm by running npm install -g typescript.

Run make all. Then open the file install/index.html in a web browser. That's it.

What this is / how to make your own

The important files in this repository are src/app.nim and src/tsGlue.ts. Together these form the WebGL app. The TypeScript file sets up the WebGL context and provides some helper functions. The Nim file does all the drawing.

When you run make all, the index.html and style.css files are copied from static/ to install/; tsc converts tsGlue.ts to a js file in install/; nim2dts converts tsGlue.ts to a nim file in src/; and nim converts app.nim to a js file in install/.

The file nim2dts creates, tsGlue.nim, is worth explaining. It contains nothing but declarations. It has declarations for the types of every symbol in tsGlue. It also contains all the declarations from the TypeScript standard library. app.nim imports the declarations file, and this allows the code in app.nim not just to use the functions and variables in tsGlue, but to use the standard JavaScript functionality such as WebGLContext itself.

If you wanted to adapt this to write your own application, all you really need to do is make sure you retain the tsGlue.ts file somewhere. If you add more nim files, all they need to do is import tsGlue. If you add more TypeScript files, then if you want the symbols from those files to be visible to Nim you'll need to add /// <reference path="src/yourTsFileHere.ts"/> to the start of tsGlue.ts. Because dts2nim ropes in the entire standard library every time it creates a nim file, I don't recommend trying to call it on multiple files in a single project.

License

The files in this package are available under the Creative Commons Zero license. In other words you may treat the files as public domain. If you are republishing this source code as sample code, then a credit to the original author (Andi McClure, <[email protected]>) would be appreciated but is not required.

nim-webgl-example's People

Contributors

mcclure avatar

Stargazers

Guido Schmidt avatar Nick Zizic avatar jtianling avatar  avatar Andres Mariscal avatar Andrea Ferretti avatar Joseph avatar

Watchers

 avatar James Cloos avatar  avatar  avatar

Forkers

kauderk

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.