1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

hot code reloading examples

This commit is contained in:
Alexander Medvednikov
2019-07-07 21:46:21 +02:00
parent af19aa5096
commit de8dc4cddb
9 changed files with 210 additions and 70 deletions

View File

@@ -641,7 +641,7 @@ pub fn (s string) ustring_tmp() ustring {
return res
}
fn (u ustring) substr(start, end int) string {
pub fn (u ustring) substr(start, end int) string {
start = u.runes[start]
if end >= u.runes.len {
end = u.s.len
@@ -652,11 +652,11 @@ fn (u ustring) substr(start, end int) string {
return u.s.substr(start, end)
}
fn (u ustring) left(pos int) string {
pub fn (u ustring) left(pos int) string {
return u.substr(0, pos)
}
fn (u ustring) right(pos int) string {
pub fn (u ustring) right(pos int) string {
return u.substr(pos, u.len)
}

View File

@@ -66,6 +66,7 @@ import const (
struct C.stat {
st_size int
st_mode int
st_mtime int
}
struct C.DIR {
@@ -640,6 +641,16 @@ pub fn signal(signum int, handler voidptr) {
C.signal(signum, handler)
}
pub fn file_last_mod_unix(path string) int {
attr := C.stat{}
//# struct stat attr;
C.stat(path.str, &attr)
//# stat(path.str, &attr);
return attr.st_mtime
//# return attr.st_mtime ;
}
fn log(s string) {
}

View File

@@ -25,6 +25,7 @@ struct C.PGResult { }
fn C.PQconnectdb(a byteptr) *C.PGconn
fn C.PQerrorMessage(voidptr) byteptr
fn C.PQgetvalue(voidptr, int, int) byteptr
pub fn connect(dbname, user string) DB {
conninfo := 'host=localhost user=$user dbname=$dbname'
@@ -46,7 +47,7 @@ fn res_to_rows(res voidptr) []pg.Row {
mut row := Row{}
for j := 0; j < nr_cols; j++ {
val := C.PQgetvalue(res, i, j)
row.vals << string(val)
row.vals << string(val)
}
rows << row
}