Advertisement
sylvanaar

Untitled

Nov 21st, 2011
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.10 KB | None | 0 0
  1. local LUA_ORG_DOCUMENTATION_URL = "http://www.lua.org/manual/5.1/manual.html"
  2. local BASE_JAR_URL = getBaseJarUrl()
  3. local LOCAL_LUA_DOCS
  4.  
  5. LOCAL_LUA_DOCS = BASE_JAR_URL and (BASE_JAR_URL.."/docs/lua-manual.html")
  6.  
  7. --- Quickhelp Documentation (ctrl-Q)
  8. -- This is called when the user invokes quick help via ctrl-q, or by
  9. -- having the quickhelp panel open and set to autolookup
  10. -- @param name The name to get documentation for.
  11. -- @return the documentation as an HTML or plain text string
  12. function getDocumentation(name)
  13.     local data = fetchURL(LOCAL_LUA_DOCS or LUA_ORG_DOCUMENTATION_URL)
  14.  
  15.     if not data then return end
  16.  
  17.     local tofind = [[<a name="pdf-]] .. name .. [[">]]
  18.  
  19.     local start = data:find(tofind, 1, true)
  20.  
  21.     if not start then return end
  22.  
  23.     local pre_start = start
  24.     for i = start-2, 1, -1 do
  25.         if data:sub(i, i) == "<" then
  26.             pre_start = i
  27.             break
  28.         end
  29.     end
  30.  
  31.     local finish = data:find("<h.>", start)
  32.  
  33.     if finish == nil then finish = -1 end
  34.  
  35.     local result = data:sub(pre_start, finish)
  36.  
  37.     result = "<html>" .. result:gsub("<p>", "<br><br>") .. "</html>"
  38.    
  39.     return result:gsub("#pdf%-", "doc_element://")
  40. end
  41. --- External Documentation URL (shift-F1)
  42. -- This is called by shift-F1 on the symbol, or by the
  43. -- external documentation button on the quick help panel
  44. -- @param name The name to get documentation for.
  45. -- @return the URL of the external documentation
  46. function getDocumentationUrl(name)
  47.     local result = LUA_ORG_DOCUMENTATION_URL .. "#pdf-" .. name
  48.  
  49.     return result
  50. end
  51.  
  52.  
  53. --- Quick Navigation Tooltip Text, (ctrl-hover on symbol)
  54. -- This is called when the user ctrl-hovers over a symbol
  55. -- @param name The name to get documentation for.
  56. -- @return the documentation as a plain text string
  57. function getQuickNavigateDocumentation(name)
  58.     local sig = SIGNATURES[name]
  59.     if not sig then return end
  60.  
  61.     if type(sig) == "table" then
  62.         sig = sig[1]
  63.     end
  64.  
  65.     return "[Lua API]\r\n " .. sig
  66. end
  67.  
  68. SIGNATURES = {
  69.  
  70. assert  = [=[ "assert (v [, message])",]=],
  71. collectgarbage  = [=[collectgarbage (opt [, arg])]=],
  72. dofile  = [=[dofile (filename)]=],
  73. error  = [=[error (message [, level])]=],
  74. _G  = [=[(table)]=],
  75. getfenv  = [=[getfenv ([f])]=],
  76. getmetatable  = [=[getmetatable (object)]=],
  77. ipairs  = [=[ipairs (t)]=],
  78. load  = [=[load (func [, chunkname])]=],
  79. loadfile  = [=[loadfile ([filename])]=],
  80. loadstring  = [=[loadstring (string [, chunkname])]=],
  81. next  = [=[next (table [, index])]=],
  82. pairs  = [=[pairs (t)]=],
  83. pcall  = [=[pcall (f, arg1, ...)]=],
  84. print  = [=[print (...)]=],
  85. rawequal  = [=[rawequal (v1, v2)]=],
  86. rawget  = [=[rawget (table, index)]=],
  87. rawset  = [=[rawset (table, index, value)]=],
  88. select  = [=[select (index, ...)]=],
  89. setfenv  = [=[setfenv (f, table)]=],
  90. setmetatable  = [=[setmetatable (table, metatable)]=],
  91. tonumber  = [=[tonumber (e [, base])]=],
  92. tostring  = [=[tostring (e)]=],
  93. type  = [=[type (v)]=],
  94. unpack  = [=[unpack (list [, i [, j]])]=],
  95. _VERSION  = [=[(string)]=],
  96. xpcall  = [=[xpcall (f, err)]=],
  97. module  = [=[module (name [, ...])]=],
  98. require  = [=[require (modname)]=],
  99.  
  100. coroutine  = { [=[(table) coroutine manipulation library]=], },
  101. debug  = { [=[(table) debug facilities library]=], },
  102. io  =  { [=[(table) I/O library]=], },
  103. math  = { [=[(table) math functions libary]=], },
  104. os  = { [=[(table) OS facilities library]=], },
  105. package  = { [=[(table) package library]=], },
  106. string  = { [=[(table) string manipulation library]=], },
  107. table  = { [=[(table) table manipulation library]=], },
  108.  
  109. ["coroutine.create"] = [=[coroutine.create (f)]=],
  110. ["coroutine.resume"] = [=[coroutine.resume (co [, val1, ...])]=],
  111. ["coroutine.running"] = [=[coroutine.running ()]=],
  112. ["coroutine.status"] = [=[coroutine.status (co)]=],
  113. ["coroutine.wrap"] = [=[coroutine.wrap (f)]=],
  114. ["coroutine.yield"] = [=[coroutine.yield (...)]=],
  115.  
  116. ["debug.debug"] = [=[debug.debug ()]=],
  117. ["debug.getfenv"] = [=[debug.getfenv (o)]=],
  118. ["debug.gethook"] = [=[debug.gethook ([thread])]=],
  119. ["debug.getinfo"] = [=[debug.getinfo ([thread,] function [, what])]=],
  120. ["debug.getlocal"] = [=[debug.getlocal ([thread,] level, local)]=],
  121. ["debug.getmetatable"] = [=[debug.getmetatable (object)]=],
  122. ["debug.getregistry"] = [=[debug.getregistry ()]=],
  123. ["debug.getupvalue"] = [=[debug.getupvalue (func, up)]=],
  124. ["debug.setfenv"] = [=[debug.setfenv (object, table)]=],
  125. ["debug.sethook"] = [=[debug.sethook ([thread,] hook, mask [, count])]=],
  126. ["debug.setlocal"] = [=[debug.setlocal ([thread,] level, local, value)]=],
  127. ["debug.setmetatable"] = [=[debug.setmetatable (object, table)]=],
  128. ["debug.setupvalue"] = [=[debug.setupvalue (func, up, value)]=],
  129. ["debug.traceback"] = [=[debug.traceback ([thread,] [message] [, level])]=],
  130.  
  131. ["io.close"] = [=[io.close ([file])]=],
  132. ["io.flush"] = [=[io.flush ()]=],
  133. ["io.input"] = [=[io.input ([file])]=],
  134. ["io.lines"] = [=[io.lines ([filename])]=],
  135. ["io.open"] = [=[io.open (filename [, mode])]=],
  136. ["io.output"] = [=[io.output ([file])]=],
  137. ["io.popen"] = [=[io.popen (prog [, mode])]=],
  138. ["io.read"] = [=[io.read (...)]=],
  139. ["io.tmpfile"] = [=[io.tmpfile ()]=],
  140. ["io.type"] = [=[io.type (obj)]=],
  141. ["io.write"] = [=[io.write (...)]=],
  142.  
  143. ["math.abs"] = [=[math.abs (x)]=],
  144. ["math.acos"] = [=[math.acos (x)]=],
  145. ["math.asin"] = [=[math.asin (x)]=],
  146. ["math.atan"] = [=[math.atan (x)]=],
  147. ["math.atan2"] = [=[math.atan2 (y, x)]=],
  148. ["math.ceil"] = [=[math.ceil (x)]=],
  149. ["math.cos"] = [=[math.cos (x)]=],
  150. ["math.cosh"] = [=[math.cosh (x)]=],
  151. ["math.deg"] = [=[math.deg (x)]=],
  152. ["math.exp"] = [=[math.exp (x)]=],
  153. ["math.floor"] = [=[math.floor (x)]=],
  154. ["math.fmod"] = [=[math.fmod (x, y)]=],
  155. ["math.frexp"] = [=[math.frexp (x)]=],
  156. ["math.huge"] = [=[math.huge]=],
  157. ["math.ldexp"] = [=[math.ldexp (m, e)]=],
  158. ["math.log"] = [=[math.log (x)]=],
  159. ["math.log10"] = [=[math.log10 (x)]=],
  160. ["math.max"] = [=[math.max (x, ...)]=],
  161. ["math.min"] = [=[math.min (x, ...)]=],
  162. ["math.modf"] = [=[math.modf (x)]=],
  163. ["math.pi"] = [=[math.pi]=],
  164. ["math.pow"] = [=[math.pow (x, y)]=],
  165. ["math.rad"] = [=[math.rad (x)]=],
  166. ["math.random"] = [=[math.random ([m [, n]])]=],
  167. ["math.randomseed"] = [=[math.randomseed (x)]=],
  168. ["math.sin"] = [=[math.sin (x)]=],
  169. ["math.sinh"] = [=[math.sinh (x)]=],
  170. ["math.sqrt"] = [=[math.sqrt (x)]=],
  171. ["math.tan"] = [=[math.tan (x)]=],
  172. ["math.tanh"] = [=[math.tanh (x)]=],
  173.  
  174. ["os.clock"] = [=[os.clock ()]=],
  175. ["os.date"] = [=[os.date ([format [, time]])]=],
  176. ["os.difftime"] = [=[os.difftime (t2, t1)]=],
  177. ["os.execute"] = [=[os.execute ([command])]=],
  178. ["os.exit"] = [=[os.exit ([code])]=],
  179. ["os.getenv"] = [=[os.getenv (varname)]=],
  180. ["os.remove"] = [=[os.remove (filename)]=],
  181. ["os.rename"] = [=[os.rename (oldname, newname)]=],
  182. ["os.setlocale"] = [=[os.setlocale (locale [, category])]=],
  183. ["os.time"] = [=[os.time ([table])]=],
  184. ["os.tmpname"] = [=[os.tmpname ()]=],
  185.  
  186. ["package.cpath"] = [=[package.cpath]=],
  187. ["package.loaded"] = [=[package.loaded]=],
  188. ["package.loaders"] = [=[package.loaders]=],
  189. ["package.loadlib"] = [=[package.loadlib (libname, funcname)]=],
  190. ["package.path"] = [=[package.path]=],
  191. ["package.preload"] = [=[package.preload]=],
  192. ["package.seeall"] = [=[package.seeall (module)]=],
  193.  
  194. ["string.byte"] = [=[string.byte (s [, i [, j]])]=],
  195. ["string.char"] = [=[string.char (...)]=],
  196. ["string.dump"] = [=[string.dump (function)]=],
  197. ["string.find"] = [=[string.find (s, pattern [, init [, plain]])]=],
  198. ["string.format"] = [=[string.format (formatstring, ...)]=],
  199. ["string.gmatch"] = [=[string.gmatch (s, pattern)]=],
  200. ["string.gsub"] = [=[string.gsub (s, pattern, repl [, n])]=],
  201. ["string.len"] = [=[string.len (s)]=],
  202. ["string.lower"] = [=[string.lower (s)]=],
  203. ["string.match"] = [=[string.match (s, pattern [, init])]=],
  204. ["string.rep"] = [=[string.rep (s, n)]=],
  205. ["string.reverse"] = [=[string.reverse (s)]=],
  206. ["string.sub"] = [=[string.sub (s, i [, j])]=],
  207. ["string.upper"] = [=[string.upper (s)]=],
  208.  
  209. ["table.concat"] = [=[table.concat (table [, sep [, i [, j]]])]=],
  210. ["table.insert"] = [=[table.insert (table, [pos,] value)]=],
  211. ["table.maxn"] = [=[table.maxn (table)]=],
  212. ["table.remove"] = [=[table.remove (table [, pos])]=],
  213. ["table.sort"] = [=[table.sort (table [, comp])]=],
  214.  
  215. }
  216.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement