mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2025-12-06 08:46:53 +08:00
Fixing cheatsheet.md namespace documentation
This commit is contained in:
parent
c45be80bf5
commit
96d2eddce1
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user