Skip to content

Instantly share code, notes, and snippets.

@mizchi
Created August 13, 2013 09:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mizchi/6219553 to your computer and use it in GitHub Desktop.
Save mizchi/6219553 to your computer and use it in GitHub Desktop.
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