Skip to content

Commit

Permalink
fix markdownlint warnings (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ozan HACIBEKİROĞLU authored Mar 4, 2020
1 parent 73b5e62 commit a053476
Show file tree
Hide file tree
Showing 18 changed files with 287 additions and 288 deletions.
13 changes: 6 additions & 7 deletions docs/builtins.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,13 @@ for more details on type conversion.
x := string(123) // x == "123"
```


Optionally it can take the second argument, which will be returned if the first
argument cannot be converted to string. Note that the second argument does not
have to be string.

```golang
v = string(undefined, "foo") // v == "foo"
v = string(undefined, false) // v == false
v = string(undefined, false) // v == false
```

## int
Expand All @@ -172,7 +171,7 @@ to be int.

```golang
v = int(undefined, 10) // v == 10
v = int(undefined, false) // v == false
v = int(undefined, false) // v == false
```

## bool
Expand Down Expand Up @@ -201,7 +200,7 @@ have to be float.

```golang
v = float(undefined, 19.84) // v == 19.84
v = float(undefined, false) // v == false
v = float(undefined, false) // v == false
```

## char
Expand All @@ -220,7 +219,7 @@ have to be float.

```golang
v = char(undefined, 'X') // v == 'X'
v = char(undefined, false) // v == false
v = char(undefined, false) // v == false
```

## bytes
Expand All @@ -239,7 +238,7 @@ have to be float.

```golang
v = bytes(undefined, bytes("foo")) // v == bytes("foo")
v = bytes(undefined, false) // v == false
v = bytes(undefined, false) // v == false
```

If you pass an int to `bytes()` function, it will create a new byte object with
Expand Down Expand Up @@ -293,7 +292,7 @@ Returns `true` if the object's type is undefined. Or it returns `false`.

Returns `true` if the object's type is function or closure. Or it returns
`false`. Note that `is_function` returns `false` for builtin functions and
user-provided callable objects.
user-provided callable objects.

## is_callable

Expand Down
29 changes: 18 additions & 11 deletions docs/formatting.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@

The format 'verbs' are derived from Go's but are simpler.

## The verbs:
## The verbs

## General

## General:
```
%v the value in a default format
%T a Go-syntax representation of the type of the value
%% a literal percent sign; consumes no value
```

## Boolean:
## Boolean

```
%t the word true or false
```

## Integer:
## Integer

```
%b base 2
%c the character represented by the corresponding Unicode code point
Expand All @@ -29,7 +32,8 @@ The format 'verbs' are derived from Go's but are simpler.
%U Unicode format: U+1234; same as "U+%04X"
```

## Float:
## Float

```
%b decimalless scientific notation with exponent a power of two,
in the manner of Go's strconv.FormatFloat with the 'b' format,
Expand All @@ -44,30 +48,32 @@ e.g. -123456p-78
%X upper-case hexadecimal notation, e.g. -0X1.23ABCP+20
```

## String and Bytes:
## String and Bytes

```
%s the uninterpreted bytes of the string or slice
%q a double-quoted string safely escaped with Go syntax
%x base 16, lower-case, two characters per byte
%X base 16, upper-case, two characters per byte
```

## Default format for %v:
## Default format for %v

```
Bool: %t
Int: %d
Float: %g
String: %s
```

## Compound Objects:
## Compound Objects

```
Array: [elem0 elem1 ...]
Maps: {key1:value1 key2:value2 ...}
```


## Width and Precision:
## Width and Precision

Width is specified by an optional decimal number immediately preceding the verb.
If absent, the width is whatever is necessary to represent the value.
Expand Down Expand Up @@ -111,7 +117,8 @@ For complex numbers, the width and precision apply to the two components
independently and the result is parenthesized, so %f applied to 1.2+3.4i
produces (1.200000+3.400000i).

## Other flags:
## Other flags

```
+ always print a sign for numeric values;
guarantee ASCII-only output for %q (%+q)
Expand Down
90 changes: 44 additions & 46 deletions docs/interoperability.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Interoperability

## Table of Contents
## Table of Contents

- [Using Scripts](#using-scripts)
- [Type Conversion Table](#type-conversion-table)
Expand Down Expand Up @@ -52,41 +52,41 @@ output variable is accessed through

```golang
import (
"fmt"
"fmt"

"github.com/d5/tengo/v2"
"github.com/d5/tengo/v2"
)

func main() {
s := tengo.NewScript([]byte(`a := b + 20`))

// define variable 'b'
_ = s.Add("b", 10)

// compile the source
c, err := s.Compile()
if err != nil {
panic(err)
}

// run the compiled bytecode
// a compiled bytecode 'c' can be executed multiple times without re-compiling it
if err := c.Run(); err != nil {
panic(err)
}

// retrieve value of 'a'
a := c.Get("a")
fmt.Println(a.Int()) // prints "30"
// re-run after replacing value of 'b'
if err := c.Set("b", 20); err != nil {
panic(err)
}
if err := c.Run(); err != nil {
panic(err)
}
fmt.Println(c.Get("a").Int()) // prints "40"
s := tengo.NewScript([]byte(`a := b + 20`))

// define variable 'b'
_ = s.Add("b", 10)

// compile the source
c, err := s.Compile()
if err != nil {
panic(err)
}

// run the compiled bytecode
// a compiled bytecode 'c' can be executed multiple times without re-compiling it
if err := c.Run(); err != nil {
panic(err)
}

// retrieve value of 'a'
a := c.Get("a")
fmt.Println(a.Int()) // prints "30"

// re-run after replacing value of 'b'
if err := c.Set("b", 20); err != nil {
panic(err)
}
if err := c.Run(); err != nil {
panic(err)
}
fmt.Println(c.Get("a").Int()) // prints "40"
}
```

Expand Down Expand Up @@ -129,7 +129,6 @@ converts Go values into Tengo values based on the following conversion table.
|`[]interface{}`|`Array`|individual elements converted to Tengo objects|
|`Object`|`Object`|_(no type conversion performed)_|


### User Types

Users can add and use a custom user type in Tengo code by implementing
Expand All @@ -144,7 +143,7 @@ more details.
To securely compile and execute _potentially_ unsafe script code, you can use
the following Script functions.

#### Script.SetImports(modules *objects.ModuleMap)
### Script.SetImports(modules *objects.ModuleMap)

SetImports sets the import modules with corresponding names. Script **does not**
include any modules by default. You can use this function to include the
Expand All @@ -169,25 +168,24 @@ mods.AddSourceModule("double", []byte(`export func(x) { return x * 2 }`))
s.SetImports(mods)
```


#### Script.SetMaxAllocs(n int64)
### Script.SetMaxAllocs(n int64)

SetMaxAllocs sets the maximum number of object allocations. Note this is a
cumulative metric that tracks only the object creations. Set this to a negative
number (e.g. `-1`) if you don't need to limit the number of allocations.
#### Script.EnableFileImport(enable bool)

### Script.EnableFileImport(enable bool)

EnableFileImport enables or disables module loading from the local files. It's
disabled by default.
disabled by default.

#### tengo.MaxStringLen
### tengo.MaxStringLen

Sets the maximum byte-length of string values. This limit applies to all
running VM instances in the process. Also it's not recommended to set or update
this value while any VM is executing.
this value while any VM is executing.

#### tengo.MaxBytesLen
### tengo.MaxBytesLen

Sets the maximum length of bytes values. This limit applies to all running VM
instances in the process. Also it's not recommended to set or update this value
Expand All @@ -200,7 +198,7 @@ times by a goroutine. If you want to run the compiled script by multiple
goroutine, you should use `Compiled.Clone` function to make a copy of Compiled
instances.

#### Compiled.Clone()
### Compiled.Clone()

Clone creates a new copy of Compiled instance. Cloned copies are safe for
concurrent use by multiple goroutines.
Expand All @@ -212,17 +210,17 @@ for i := 0; i < concurrency; i++ {
_ = compiled.Set("a", rand.Intn(10))
_ = compiled.Set("b", rand.Intn(10))
_ = compiled.Set("c", rand.Intn(10))

if err := compiled.Run(); err != nil {
panic(err)
}

// outputs
d = compiled.Get("d").Int()
e = compiled.Get("e").Int()
}(compiled.Clone()) // Pass the cloned copy of Compiled
}
```
```

## Compiler and VM

Expand Down
Loading

0 comments on commit a053476

Please sign in to comment.