GithubHelp home page GithubHelp logo

3dgen / cppwasm-book Goto Github PK

View Code? Open in Web Editor NEW
1.3K 1.3K 165.0 15.33 MB

:books: WebAssembly friendly programming with C/C++ -- Emscripten practice

Makefile 0.03% WebAssembly 2.08% Rust 0.05% C++ 73.93% JavaScript 21.48% HTML 0.87% C 1.55% Batchfile 0.01% CMake 0.01%
c cpp emscripten wasm webassembly

cppwasm-book's People

Contributors

3dgen avatar chai2010 avatar yushih avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cppwasm-book's Issues

《面向WebAssembly编程》源代码求助

两位作者你们好:
最近在看这本书,里面没有提供源代码链接,部分章节和这个代码库的内容和example路径下的文件不对应,不知道作者大大有没有兴趣提供一个代码库链接方便同学们编译和运行。

抽奖送3本<WebAssembly标准入门>图书

抽奖链接

#4


<WebAssembly标准入门>相关链接:

几个有意思的例子(基于asm.js):


公平公正的抽奖规则

抽奖规则的设计原则:

  • 组织方和参与者均有参与感
  • 抽奖的结果可重现,但是开奖之前无法预支结果

收集参与抽奖的人

  • 必须有github账号,并在这个issue留言参与抽奖
  • github账号必须2018年之前申请的
  • 只接受大陆普通快递可达地区

抽奖的流程

  1. 开始前,大家可以验证规则是否有缺陷,有任何问题都可以讨论
  2. 我在抽奖正式开始时(可以提前参与),会准备一个秘密的字符串作为种子,然后先公布种子字符串的MD5,同时公布截止的规则(可以是ID达到一个数量, 或者是设置一个截止时间里程碑)
  3. 参与抽象的同学回复一个幸运字符串([0-9a-zA-Z-_]等字符组成,1-32个字符),也可以用自己的账号(如果用户如果担心泄密,也可以公布MD5)
  4. 开奖前我公布作为种子的秘密字符串,大家可以验证MD5,以防止我作弊
  5. 开奖前,参与者如果是提供MD5的也需要公布自己的幸运字符串,大家也去验证
  6. 每个ID和秘密的种子字符串各生成一个对应的crc32数字,最后把数字加起来对人数取模就是中奖号
  7. 每个ID作为utf8字符串排序,排序后的位置就是每个ID的抽奖号码
  8. 在开奖后和结果公布之前,会锁定这个issue,之后会再重新打开
  9. 抽完一个之后删除中奖ID,继续上述流程
  10. 任何人可以验证结果

补充点:

  • 有任何疑问请加入 QQ群 (726475047) 讨论
  • 如果用户以MD5公布的幸运号,那么在抽奖截止后要公布真实的幸运号,否则作废
  • 如果担心MD5不够安全,可以加盐,比如 abc:sdfsd 生成的MD5, abc是幸运号,冒号后面是salt
  • 每个账号如果回复多个幸运字符串,以开奖前的最后一个为准
  • chai2010和ending不参与

抽奖的代码(Go语言实现)

下面是抽奖算法的例子,种子字符串是wasm,2各参与者:

// Copyright 2018 [email protected]. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
	"fmt"
	"hash/crc32"
	"sort"
)

func main() {
	luckyStar := MakeLuckyStar("wasm", map[string]string{
		"chai2010": "chai2010",
		"ending":   "ending",
	})

	fmt.Println(luckyStar)
	// output: ending
}

func MakeLuckyStar(seed string, luckyTokens map[string]string) string {
	var (
		crc32Sum   = uint64(crc32.ChecksumIEEE([]byte(seed)))
		sortedKeys = make([]string, 0, len(luckyTokens))
	)

	for id, tok := range luckyTokens {
		crc32Sum += uint64(crc32.ChecksumIEEE([]byte(tok)))
		sortedKeys = append(sortedKeys, id)
	}
	sort.Strings(sortedKeys)

	idx := int(crc32Sum) % len(luckyTokens)
	return sortedKeys[idx]
}

https://play.golang.org/p/mox2zhbde49

emcc 2.0.13 Pointer_stringify问题

emcc 2.0.13版本
使用 Pointer_stringify() 会报错 Pointer_stringify is not defined (使用第五章例子 websocket)
可用UTF8ToString替换

this function has been removed - you should use UTF8ToString(ptr, maxBytesToRead) instead! 文中使用的方法已经被移除了!

this function has been removed - you should use UTF8ToString(ptr, maxBytesToRead) instead!
hello.js:2400 this function has been removed - you should use UTF8ToString(ptr, maxBytesToRead) instead!
abort @ hello.js:2400
Pointer_stringify @ hello.js:806
Module.onRuntimeInitialized @ app.js:3
doRun @ hello.js:2309
run @ hello.js:2326
runCaller @ hello.js:2275
removeRunDependency @ hello.js:1535
receiveInstance @ hello.js:1653
receiveInstantiatedSource @ hello.js:1670
Promise.then (async)
(anonymous) @ hello.js:1691
Promise.then (async)
instantiateAsync @ hello.js:1689
createWasm @ hello.js:1716
Module.asm @ hello.js:1740
(anonymous) @ hello.js:2082
app.js:6 Uncaught (in promise) abort(this function has been removed - you should use UTF8ToString(ptr, maxBytesToRead) instead!) at Error
at jsStackTrace (http://127.0.0.1:8080/output/hello.js:1808:17)
at stackTrace (http://127.0.0.1:8080/output/hello.js:1825:16)
at abort (http://127.0.0.1:8080/output/hello.js:2406:44)
at Pointer_stringify (http://127.0.0.1:8080/output/hello.js:806:3)
at Object.Module.onRuntimeInitialized (http://127.0.0.1:8080/app.js:3:3)
at doRun (http://127.0.0.1:8080/output/hello.js:2309:71)
at run (http://127.0.0.1:8080/output/hello.js:2326:5)
at runCaller (http://127.0.0.1:8080/output/hello.js:2275:19)
at removeRunDependency (http://127.0.0.1:8080/output/hello.js:1535:7)
at receiveInstance (http://127.0.0.1:8080/output/hello.js:1653:5)
Module.onRuntimeInitialized @ app.js:6
doRun @ hello.js:2309
run @ hello.js:2326
runCaller @ hello.js:2275
removeRunDependency @ hello.js:1535
receiveInstance @ hello.js:1653
receiveInstantiatedSource @ hello.js:1670
Promise.then (async)
(anonymous) @ hello.js:1691
Promise.then (async)
instantiateAsync @ hello.js:1689
createWasm @ hello.js:1716
Module.asm @ hello.js:1740
(anonymous) @ hello.js:2082

Translation in other languages

Hi,
Will you translate these documents in english ? It would be very pleasant. i'm interested in the subject but I don't understand what you say about it.
Thank you for your reply.

两个c的库如何编译到自己的工程

真的很开心有**人在深入搞webassmebly,现在想请教一个问题:
我工程中有两个库a.h和b.h这两个都是第三方库,我现在又写了一个c.h引用了这两个库,并且都已经调通了,但是我在使用webassmebly打包c.h时候遇见了问题,我不知道如何让它找到a.h和b.h。
感谢您能回复。

申请转载书籍《C/C++面向WebAssembly编程》

您好,我是书栈网( https://www.bookstack.cn )站长,最近在收集查找和分享WebAssembly的学习资料,看到了您创作的《C/C++面向WebAssembly编程》托管在github上,由于并未看到 CC 协议,所以在此申请,希望能够将该优质的内容转载分发到网站上,方便更多的用户使用和阅读。我们的转载会遵循 知识共享-署名-非商用 的知识共享协议。

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.