我是meteor和coffeescript的新手.我正在使用非官方流星常见问题解答中建议的文件布局.在文件集/ C.coffee中,我有
C = new Meteor.Collection 'C'
console.log "C: #{C}"
Run Code Online (Sandbox Code Playgroud)
在文件服务器/ main.coffee中,我有
C.insert {test: 'test'}
Run Code Online (Sandbox Code Playgroud)
当我启动流星时,我在控制台上看到:
C: [object Object]
ReferenceError: C is not defined
at app/server/main.coffee.js:5:1
at /home/xxx/yyy/.meteor/local/build/server/server.js:298:12
Run Code Online (Sandbox Code Playgroud)
如何在collections/C.coffee之外的文件中提供C?
更新:添加@到C修复了顶级问题.但它仍然失败:
Meteor.methods
test: (statement) ->
@C.insert {test: 'test'}
Run Code Online (Sandbox Code Playgroud)
它失败并出现错误 TypeError: Cannot call method 'insert' of undefined
是否可以将类方法作为参数传递给模板?例如:
template<typename T, void(T::*TFun)()>
void call(T* x) {
x->TFun();
}
struct Y {
void foo();
};
int main() {
Y y;
call<Y,&Y::foo>(&y); // should be the equivalent of y.foo()
}
Run Code Online (Sandbox Code Playgroud)
如果我尝试编译上述内容,我会得到:
main.cpp: In instantiation of void call(T*) [with T = Y; void (T::* TFun)() = &Y::foo]:
main.cpp:12:23: required from here
main.cpp:4:5: error: struct Y has no member named TFun
x->TFun();
^
Run Code Online (Sandbox Code Playgroud)
这可能吗,如果可能,语法是什么?
我正在尝试使用 FParsec 解析 C 风格注释。不知道为什么会失败:
我的解析器代码:
let openComment : Parser<_,unit> = pstring "/*"
let closeComment : Parser<_,unit> = pstring "*/"
let comment = pstring "//" >>. restOfLine true
<|> openComment >>. (charsTillString "*/" true System.Int32.MaxValue) |>> Comment
//<|> openComment >>. manyCharsTill anyChar closeComment |>> Comment
let spaceComments = many ((spaces1 |>> IgnoreU) <|> comment)
let str s = spaceComments >>. pstring s .>> spaceComments
Run Code Online (Sandbox Code Playgroud)
测试线束:
let testStr = @"
// test comment
/* a block comment
*/
x // another …Run Code Online (Sandbox Code Playgroud)