Created
August 13, 2013 09:46
-
-
Save mizchi/6219553 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fs = require "fs" | |
eco = require 'eco' | |
RPC = {} | |
header = ''' | |
class Struct | |
class Request | |
''' | |
type_template = ''' | |
<%- "\# #{@description}" if @description %> | |
class <%- @name %> extends Struct | |
@__type__: | |
<% for key, val of @params: %> | |
<%- key %>: <%- val %> | |
<% end %> | |
constructor: (p)-> | |
<% for key, val of @params: %> | |
@<%- key %> = p.<%- key %> | |
<% end %> | |
''' | |
RPC.type = (name, fn) -> | |
hoge = name: name | |
fn(hoge) | |
console.log eco.render type_template, hoge | |
func_template = ''' | |
<%- "\# #{@description}" if @description %> | |
class Request_<%- @name %> extends Request | |
@__args__: [ | |
<% for arg in @args: %> | |
{ | |
<% for key, val of arg: %> | |
<%- key %>: <%- val %> | |
<% end %> | |
} | |
<% end %> | |
] | |
@__return_type__: | |
<% for key, val of @return_type: %> | |
<%- key %>: <%- val %> | |
<% end %> | |
constructor: (args...)-> | |
<% for arg, i in @args: %> <% for key, val of arg: %> | |
@<%- key %> = args[<%- i %>] | |
<% end %> <% end %> | |
''' | |
RPC.func = (name, fn)-> | |
obj = name: name | |
fn obj | |
console.log eco.render func_template, obj | |
# xxxxxxxxxxxxxxxxxx | |
console.log header | |
RPC.type 'Point', (f) -> | |
f.params = | |
x: 'Number' | |
y: 'Number' | |
f.description = '座標' | |
RPC.func "getPosition", (f) -> | |
f.args = [ | |
{userName:'String'} | |
{userId :'Number'} | |
] | |
f.return_type = | |
point: "Point" | |
f.description = 'ユーザーの位置を取得' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment