FedericoCeratto / nim-fswatch

Nim wrapper for the fswatch library
GNU General Public License v3.0
8 stars 1 forks source link

OS X - template/generic instantiation of `setCallback` from here #1

Open mikebelanger opened 4 years ago

mikebelanger commented 4 years ago

Hello!

Promising wrappers here! Unfortunately I can't quite get it to run, but maybe I'm doing it wrong.

When I try running the example code, I get an error on line 5, the monitor.setCallback(callback). Its template/generic instantiation of `setCallback` from here. And another, monitor.start() gives the error Error: undeclared identifier: 'data'. I'm guessing the first error is related to the first error though.

Judging from this project's README, this has only been tested on Linux. So I changed the library's libfswatch_fn variable in libsfwatch.nim file to const libfswatch_fn* = "/usr/local/Cellar/fswatch/1.14.0/lib/libfswatch.11.dylib", which is the path to my lib on os x. But I still get the same error after changing this.

If I'm just doing something plain wrong, please let me know and close the issue. Thanks!

jasonk000 commented 4 years ago

You need to create a data var in the same scope as which your monitor is started and the containers cb is present.

mikebelanger commented 4 years ago

@jasonk000 ah thanks! I created a var globally in the example like

import times, fswatch
var data = ""

var monitor = newMonitor(latency=0.01)
monitor.add("/Users/mikebelanger/Dev/Personal/nim_filewatcher/some_file.txt")

proc callback(eg: EventGroup) =
  for e in eg:
    echo e.path, " ", $e.kind, " ", e.time.utc()

monitor.setCallback(callback)

# blocks here
monitor.start()

Should this go into the main example? Or is it so simple that most dev's would get this anyway?

Also, For any other mac (brew) users: changing the libfswatch.nim's libfswatch_fn to "/usr/local/Cellar/fswatch/1.14.0/lib/libfswatch.11.dylib" was necessary as well.

mikebelanger commented 4 years ago

Better yet I created a PR to show what's worked for me.