1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
Leah Lundqvist
2020-12-08 17:49:20 +01:00
committed by GitHub
parent a2ec52b8c4
commit 90c1c639fe
8 changed files with 476 additions and 223 deletions

View File

@ -4,14 +4,18 @@
module builtin
fn (a any) toString()
pub fn println(s any) {
JS.console.log(s)
// Quickfix to properly print basic types
// TODO: Add proper detection code for this
JS.console.log(s.toString())
}
pub fn print(s any) {
// TODO
// $if js.node {
JS.process.stdout.write(s)
JS.process.stdout.write(s.toString())
// } $else {
// panic('Cannot `print` in a browser, use `println` instead')
// }

View File

@ -7,6 +7,23 @@
module builtin
pub struct JS.Number {}
pub struct JS.String {
length JS.Number
}
pub struct JS.Boolean {}
pub struct JS.Array {}
pub struct JS.Map {}
// Type prototype functions
fn (v JS.String) toString() JS.String
fn (v JS.Number) toString() JS.String
fn (v JS.Boolean) toString() JS.String
fn (v JS.Array) toString() JS.String
fn (v JS.Map) toString() JS.String
fn (v JS.String) slice(a int, b int) JS.String
// Top level functions
fn JS.eval(string) any
fn JS.parseInt(string, f64) f64
@ -63,3 +80,7 @@ fn JS.Math.round(f64) f64
fn JS.Math.sin(f64) f64
fn JS.Math.sqrt(f64) f64
fn JS.Math.tan(f64) f64
// JSON
fn JS.JSON.stringify(any) string
fn JS.JSON.parse(string) any

9
vlib/builtin/js/string.v Normal file
View File

@ -0,0 +1,9 @@
module builtin
pub struct string {
str JS.String
}
pub fn (s string) slice(a int, b int) string {
return string(s.str.slice(a, b))
}