forked from gamesensical/docs
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build_emmylua.rb
47 lines (36 loc) · 1.26 KB
/
build_emmylua.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require "bundler/inline"
gemfile do
source "https://rubygems.org"
require "json"
require "pathname"
gem "pry"
end
BUILD_DIR = Pathname.new("build/")
SRC_DIR = Pathname.new("src/")
globals = JSON.parse((BUILD_DIR + "globals.json").read)
contents = []
contents << "--[[EmmyLua]]"
globals.sort.each do |global, functions|
contents << ""
contents << "-- #{global}:"
contents << ""
contents << "#{global} = {}"
contents << ""
functions.each do |name, documentation|
contents << "---"
if documentation.key? "description"
contents.push(documentation["description"].split("\n").map{|ln| "--- #{ln}"})
contents << "---"
end
documentation["args"].each do |arg|
contents << "--- `#{arg["name"]}`#{arg.key?("description") ? ": #{arg["description"]}" : ""}"
end
documentation["args"].each do |arg|
contents << "---@param #{arg["name"]}#{arg.key?("type") ? " #{arg["type"]}" : ""}"
end
contents << "---@return #{documentation["return_type"]}#{documentation.key?("return_description") ? " #{documentation["return_description"]}" : ""}" if documentation.key? "return_type"
contents << "function #{global}.#{name}(#{documentation["args"].map{|arg| arg["name"]}.join(", ")}) end"
contents << ""
end
end
(BUILD_DIR + "emmylua.lua").write(contents.join("\n"))