Fixing cheatsheet.md namespace documentation

This commit is contained in:
Stephen Berry 2016-10-18 09:29:14 -05:00
parent c45be80bf5
commit 96d2eddce1

View File

@ -129,6 +129,27 @@ chai.register_namespace(math, "math");
```
Namespaces are imported to make them available for scripting
```
chai.import("math"); // importing via C++ (_not generally recommended_)
```
```
import("math") // importing via ChaiScript (_recommended_)
print(math.pi) // prints 3.14159
```
### Delayed Namespace Generation
Passing a lambda function that returns a namespace will delay the namespace generation until `import` is called.
This saves memory and computing costs if a namespace is not imported into every ChaiScript instance.
```
chai.register_namespace([]() {
chaiscript::Namespace math;
math["pi"] = chaiscript::const_var(3.14159);
math["sin"] = chaiscript::var(chaiscript::fun([](const double x) { return sin(x); }));
return math; },
"math");
```
# Using STL