luci.util.html 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html>
  4. <head>
  5. <title>Reference</title>
  6. <link rel="stylesheet" href="../luadoc.css" type="text/css" />
  7. <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/-->
  8. </head>
  9. <body>
  10. <div id="container">
  11. <div id="product">
  12. <div id="product_logo"></div>
  13. <div id="product_name"><big><b></b></big></div>
  14. <div id="product_description"></div>
  15. </div> <!-- id="product" -->
  16. <div id="main">
  17. <div id="navigation">
  18. <h1>LuaDoc</h1>
  19. <ul>
  20. <li><a href="../index.html">Index</a></li>
  21. </ul>
  22. <!-- Module list -->
  23. <h1>Modules</h1>
  24. <ul>
  25. <li>
  26. <a href="../modules/luci.dispatcher.html">luci.dispatcher</a>
  27. </li>
  28. <li>
  29. <a href="../modules/luci.http.html">luci.http</a>
  30. </li>
  31. <li>
  32. <a href="../modules/luci.http.conditionals.html">luci.http.conditionals</a>
  33. </li>
  34. <li>
  35. <a href="../modules/luci.http.date.html">luci.http.date</a>
  36. </li>
  37. <li>
  38. <a href="../modules/luci.http.mime.html">luci.http.mime</a>
  39. </li>
  40. <li>
  41. <a href="../modules/luci.i18n.html">luci.i18n</a>
  42. </li>
  43. <li>
  44. <a href="../modules/luci.ip.html">luci.ip</a>
  45. </li>
  46. <li>
  47. <a href="../modules/luci.ip.cidr.html">luci.ip.cidr</a>
  48. </li>
  49. <li>
  50. <a href="../modules/luci.json.html">luci.json</a>
  51. </li>
  52. <li>
  53. <a href="../modules/luci.jsonc.html">luci.jsonc</a>
  54. </li>
  55. <li>
  56. <a href="../modules/luci.jsonc.parser.html">luci.jsonc.parser</a>
  57. </li>
  58. <li>
  59. <a href="../modules/luci.model.ipkg.html">luci.model.ipkg</a>
  60. </li>
  61. <li>
  62. <a href="../modules/luci.model.uci.html">luci.model.uci</a>
  63. </li>
  64. <li>
  65. <a href="../modules/luci.rpcc.html">luci.rpcc</a>
  66. </li>
  67. <li>
  68. <a href="../modules/luci.rpcc.ruci.html">luci.rpcc.ruci</a>
  69. </li>
  70. <li>
  71. <a href="../modules/luci.sys.html">luci.sys</a>
  72. </li>
  73. <li>
  74. <a href="../modules/luci.sys.init.html">luci.sys.init</a>
  75. </li>
  76. <li>
  77. <a href="../modules/luci.sys.iptparser.html">luci.sys.iptparser</a>
  78. </li>
  79. <li>
  80. <a href="../modules/luci.sys.net.html">luci.sys.net</a>
  81. </li>
  82. <li>
  83. <a href="../modules/luci.sys.process.html">luci.sys.process</a>
  84. </li>
  85. <li>
  86. <a href="../modules/luci.sys.user.html">luci.sys.user</a>
  87. </li>
  88. <li>
  89. <a href="../modules/luci.sys.wifi.html">luci.sys.wifi</a>
  90. </li>
  91. <li><strong>luci.util</strong></li>
  92. <li>
  93. <a href="../modules/luci.xml.html">luci.xml</a>
  94. </li>
  95. <li>
  96. <a href="../modules/nixio.html">nixio</a>
  97. </li>
  98. <li>
  99. <a href="../modules/nixio.CHANGELOG.html">nixio.CHANGELOG</a>
  100. </li>
  101. <li>
  102. <a href="../modules/nixio.CryptoHash.html">nixio.CryptoHash</a>
  103. </li>
  104. <li>
  105. <a href="../modules/nixio.File.html">nixio.File</a>
  106. </li>
  107. <li>
  108. <a href="../modules/nixio.README.html">nixio.README</a>
  109. </li>
  110. <li>
  111. <a href="../modules/nixio.Socket.html">nixio.Socket</a>
  112. </li>
  113. <li>
  114. <a href="../modules/nixio.TLSContext.html">nixio.TLSContext</a>
  115. </li>
  116. <li>
  117. <a href="../modules/nixio.TLSSocket.html">nixio.TLSSocket</a>
  118. </li>
  119. <li>
  120. <a href="../modules/nixio.UnifiedIO.html">nixio.UnifiedIO</a>
  121. </li>
  122. <li>
  123. <a href="../modules/nixio.bin.html">nixio.bin</a>
  124. </li>
  125. <li>
  126. <a href="../modules/nixio.bit.html">nixio.bit</a>
  127. </li>
  128. <li>
  129. <a href="../modules/nixio.crypto.html">nixio.crypto</a>
  130. </li>
  131. <li>
  132. <a href="../modules/nixio.fs.html">nixio.fs</a>
  133. </li>
  134. </ul>
  135. <!-- File list -->
  136. </div><!-- id="navigation" -->
  137. <div id="content">
  138. <h1>Class <code>luci.util</code></h1>
  139. <p></p>
  140. <h2>Functions</h2>
  141. <table class="function_list">
  142. <tr>
  143. <td class="name" nowrap><a href="#append">append</a>&nbsp;(src, ...)</td>
  144. <td class="summary">
  145. Appends numerically indexed tables or single objects to a given table.</td>
  146. </tr>
  147. <tr>
  148. <td class="name" nowrap><a href="#bigendian">bigendian</a>&nbsp;()</td>
  149. <td class="summary">
  150. Test whether the current system is operating in big endian mode.</td>
  151. </tr>
  152. <tr>
  153. <td class="name" nowrap><a href="#class">class</a>&nbsp;(base)</td>
  154. <td class="summary">
  155. Create a Class object (Python-style object model).</td>
  156. </tr>
  157. <tr>
  158. <td class="name" nowrap><a href="#clone">clone</a>&nbsp;(object, deep)</td>
  159. <td class="summary">
  160. Clones the given object and return it's copy.</td>
  161. </tr>
  162. <tr>
  163. <td class="name" nowrap><a href="#cmatch">cmatch</a>&nbsp;(str, pattern)</td>
  164. <td class="summary">
  165. Count the occurrences of given substring in given string.</td>
  166. </tr>
  167. <tr>
  168. <td class="name" nowrap><a href="#combine">combine</a>&nbsp;(tbl1, tbl2, ...)</td>
  169. <td class="summary">
  170. Combines two or more numerically indexed tables and single objects into one table.</td>
  171. </tr>
  172. <tr>
  173. <td class="name" nowrap><a href="#contains">contains</a>&nbsp;(table, value)</td>
  174. <td class="summary">
  175. Checks whether the given table contains the given value.</td>
  176. </tr>
  177. <tr>
  178. <td class="name" nowrap><a href="#copcall">copcall</a>&nbsp;(f, ...)</td>
  179. <td class="summary">
  180. This is a coroutine-safe drop-in replacement for Lua's "pcall"-function
  181. </td>
  182. </tr>
  183. <tr>
  184. <td class="name" nowrap><a href="#coxpcall">coxpcall</a>&nbsp;(f, err, ...)</td>
  185. <td class="summary">
  186. This is a coroutine-safe drop-in replacement for Lua's "xpcall"-function
  187. </td>
  188. </tr>
  189. <tr>
  190. <td class="name" nowrap><a href="#dumptable">dumptable</a>&nbsp;(t, maxdepth)</td>
  191. <td class="summary">
  192. Recursively dumps a table to stdout, useful for testing and debugging.</td>
  193. </tr>
  194. <tr>
  195. <td class="name" nowrap><a href="#exec">exec</a>&nbsp;(command)</td>
  196. <td class="summary">
  197. Execute given commandline and gather stdout.</td>
  198. </tr>
  199. <tr>
  200. <td class="name" nowrap><a href="#execi">execi</a>&nbsp;(command)</td>
  201. <td class="summary">
  202. Return a line-buffered iterator over the output of given command.</td>
  203. </tr>
  204. <tr>
  205. <td class="name" nowrap><a href="#get_bytecode">get_bytecode</a>&nbsp;(val)</td>
  206. <td class="summary">
  207. Return the current runtime bytecode of the given data.</td>
  208. </tr>
  209. <tr>
  210. <td class="name" nowrap><a href="#imatch">imatch</a>&nbsp;(val)</td>
  211. <td class="summary">
  212. Return a matching iterator for the given value.</td>
  213. </tr>
  214. <tr>
  215. <td class="name" nowrap><a href="#instanceof">instanceof</a>&nbsp;(object, class)</td>
  216. <td class="summary">
  217. Test whether the given object is an instance of the given class.</td>
  218. </tr>
  219. <tr>
  220. <td class="name" nowrap><a href="#keys">keys</a>&nbsp;(t)</td>
  221. <td class="summary">
  222. Retrieve all keys of given associative table.</td>
  223. </tr>
  224. <tr>
  225. <td class="name" nowrap><a href="#kspairs">kspairs</a>&nbsp;(t)</td>
  226. <td class="summary">
  227. Return a key, value iterator for the given table.</td>
  228. </tr>
  229. <tr>
  230. <td class="name" nowrap><a href="#libpath">libpath</a>&nbsp;()</td>
  231. <td class="summary">
  232. Returns the absolute path to LuCI base directory.</td>
  233. </tr>
  234. <tr>
  235. <td class="name" nowrap><a href="#parse_units">parse_units</a>&nbsp;(ustr)</td>
  236. <td class="summary">
  237. Parse certain units from the given string and return the canonical integer
  238. value or 0 if the unit is unknown.</td>
  239. </tr>
  240. <tr>
  241. <td class="name" nowrap><a href="luci.xml.html#pcdata">pcdata</a>&nbsp;(value)</td>
  242. <td class="summary">
  243. Create valid XML PCDATA from given string.
  244. This is a wrapper for <a href="luci.xml.html#pcdata">luci.xml.pcdata()</a>.</td>
  245. </tr>
  246. <tr>
  247. <td class="name" nowrap><a href="#perror">perror</a>&nbsp;(obj)</td>
  248. <td class="summary">
  249. Write given object to stderr.</td>
  250. </tr>
  251. <tr>
  252. <td class="name" nowrap><a href="#restore_data">restore_data</a>&nbsp;(str)</td>
  253. <td class="summary">
  254. Restore data previously serialized with serialize_data().</td>
  255. </tr>
  256. <tr>
  257. <td class="name" nowrap><a href="#serialize_data">serialize_data</a>&nbsp;(val)</td>
  258. <td class="summary">
  259. Recursively serialize given data to lua code, suitable for restoring
  260. with loadstring().</td>
  261. </tr>
  262. <tr>
  263. <td class="name" nowrap><a href="#serialize_json">serialize_json</a>&nbsp;(data, writer)</td>
  264. <td class="summary">
  265. Convert data structure to JSON
  266. </td>
  267. </tr>
  268. <tr>
  269. <td class="name" nowrap><a href="#shellquote">shellquote</a>&nbsp;(value)</td>
  270. <td class="summary">
  271. Safely quote value for use in shell commands.</td>
  272. </tr>
  273. <tr>
  274. <td class="name" nowrap><a href="#spairs">spairs</a>&nbsp;(t, f)</td>
  275. <td class="summary">
  276. Return a key, value iterator which returns the values sorted according to
  277. the provided callback function.</td>
  278. </tr>
  279. <tr>
  280. <td class="name" nowrap><a href="#split">split</a>&nbsp;(str, pat, max, regex)</td>
  281. <td class="summary">
  282. Splits given string on a defined separator sequence and return a table
  283. containing the resulting substrings.</td>
  284. </tr>
  285. <tr>
  286. <td class="name" nowrap><a href="#strip_bytecode">strip_bytecode</a>&nbsp;(code)</td>
  287. <td class="summary">
  288. Strips unnecessary lua bytecode from given string.</td>
  289. </tr>
  290. <tr>
  291. <td class="name" nowrap><a href="luci.xml.html#striptags">striptags</a>&nbsp;(value)</td>
  292. <td class="summary">
  293. Strip HTML tags from given string.
  294. This is a wrapper for <a href="luci.xml.html#striptags">luci.xml.striptags()</a>.</td>
  295. </tr>
  296. <tr>
  297. <td class="name" nowrap><a href="#threadlocal">threadlocal</a>&nbsp;()</td>
  298. <td class="summary">
  299. Create a new or get an already existing thread local store associated with
  300. the current active coroutine.</td>
  301. </tr>
  302. <tr>
  303. <td class="name" nowrap><a href="#trim">trim</a>&nbsp;(str)</td>
  304. <td class="summary">
  305. Remove leading and trailing whitespace from given string value.</td>
  306. </tr>
  307. <tr>
  308. <td class="name" nowrap><a href="#ubus">ubus</a>&nbsp;(object, method, values)</td>
  309. <td class="summary">
  310. Issue an ubus call.</td>
  311. </tr>
  312. <tr>
  313. <td class="name" nowrap><a href="#update">update</a>&nbsp;(t, updates)</td>
  314. <td class="summary">
  315. Update values in given table with the values from the second given table.</td>
  316. </tr>
  317. <tr>
  318. <td class="name" nowrap><a href="#urldecode">urldecode</a>&nbsp;(str, decode_plus)</td>
  319. <td class="summary">
  320. Decode an URL-encoded string - optionally decoding the "+" sign to space.</td>
  321. </tr>
  322. <tr>
  323. <td class="name" nowrap><a href="#urlencode">urlencode</a>&nbsp;(str)</td>
  324. <td class="summary">
  325. URL-encode given string.</td>
  326. </tr>
  327. <tr>
  328. <td class="name" nowrap><a href="#vspairs">vspairs</a>&nbsp;(t)</td>
  329. <td class="summary">
  330. Return a key, value iterator for the given table.</td>
  331. </tr>
  332. </table>
  333. <br/>
  334. <br/>
  335. <h2><a name="functions"></a>Functions</h2>
  336. <dl class="function">
  337. <dt><a name="append"></a><strong>append</strong>&nbsp;(src, ...)</dt>
  338. <dd>
  339. Appends numerically indexed tables or single objects to a given table.
  340. <h3>Parameters</h3>
  341. <ul>
  342. <li>
  343. src: Target table
  344. </li>
  345. <li>
  346. ...: Objects to insert
  347. </li>
  348. </ul>
  349. <h3>Return value:</h3>
  350. Target table
  351. </dd>
  352. <dt><a name="bigendian"></a><strong>bigendian</strong>&nbsp;()</dt>
  353. <dd>
  354. Test whether the current system is operating in big endian mode.
  355. <h3>Return value:</h3>
  356. Boolean value indicating whether system is big endian
  357. </dd>
  358. <dt><a name="class"></a><strong>class</strong>&nbsp;(base)</dt>
  359. <dd>
  360. Create a Class object (Python-style object model).
  361. The class object can be instantiated by calling itself.
  362. Any class functions or shared parameters can be attached to this object.
  363. Attaching a table to the class object makes this table shared between
  364. all instances of this class. For object parameters use the __init__ function.
  365. Classes can inherit member functions and values from a base class.
  366. Class can be instantiated by calling them. All parameters will be passed
  367. to the __init__ function of this class - if such a function exists.
  368. The __init__ function must be used to set any object parameters that are not shared
  369. with other objects of this class. Any return values will be ignored.
  370. <h3>Parameters</h3>
  371. <ul>
  372. <li>
  373. base: The base class to inherit from (optional)
  374. </li>
  375. </ul>
  376. <h3>Return value:</h3>
  377. A class object
  378. <h3>See also:</h3>
  379. <ul>
  380. <li><a href="#instanceof">
  381. instanceof
  382. </a>
  383. <li><a href="#clone">
  384. clone
  385. </a>
  386. </ul>
  387. </dd>
  388. <dt><a name="clone"></a><strong>clone</strong>&nbsp;(object, deep)</dt>
  389. <dd>
  390. Clones the given object and return it's copy.
  391. <h3>Parameters</h3>
  392. <ul>
  393. <li>
  394. object: Table value to clone
  395. </li>
  396. <li>
  397. deep: Boolean indicating whether to do recursive cloning
  398. </li>
  399. </ul>
  400. <h3>Return value:</h3>
  401. Cloned table value
  402. </dd>
  403. <dt><a name="cmatch"></a><strong>cmatch</strong>&nbsp;(str, pattern)</dt>
  404. <dd>
  405. Count the occurrences of given substring in given string.
  406. <h3>Parameters</h3>
  407. <ul>
  408. <li>
  409. str: String to search in
  410. </li>
  411. <li>
  412. pattern: String containing pattern to find
  413. </li>
  414. </ul>
  415. <h3>Return value:</h3>
  416. Number of found occurrences
  417. </dd>
  418. <dt><a name="combine"></a><strong>combine</strong>&nbsp;(tbl1, tbl2, ...)</dt>
  419. <dd>
  420. Combines two or more numerically indexed tables and single objects into one table.
  421. <h3>Parameters</h3>
  422. <ul>
  423. <li>
  424. tbl1: Table value to combine
  425. </li>
  426. <li>
  427. tbl2: Table value to combine
  428. </li>
  429. <li>
  430. ...: More tables to combine
  431. </li>
  432. </ul>
  433. <h3>Return value:</h3>
  434. Table value containing all values of given tables
  435. </dd>
  436. <dt><a name="contains"></a><strong>contains</strong>&nbsp;(table, value)</dt>
  437. <dd>
  438. Checks whether the given table contains the given value.
  439. <h3>Parameters</h3>
  440. <ul>
  441. <li>
  442. table: Table value
  443. </li>
  444. <li>
  445. value: Value to search within the given table
  446. </li>
  447. </ul>
  448. <h3>Return value:</h3>
  449. Number indicating the first index at which the given value occurs
  450. within table or false.
  451. </dd>
  452. <dt><a name="copcall"></a><strong>copcall</strong>&nbsp;(f, ...)</dt>
  453. <dd>
  454. This is a coroutine-safe drop-in replacement for Lua's "pcall"-function
  455. <h3>Parameters</h3>
  456. <ul>
  457. <li>
  458. f: Lua function to be called protected
  459. </li>
  460. <li>
  461. ...: Parameters passed to the function
  462. </li>
  463. </ul>
  464. <h3>Return value:</h3>
  465. A boolean whether the function call succeeded and the returns
  466. values of the function or the error object
  467. </dd>
  468. <dt><a name="coxpcall"></a><strong>coxpcall</strong>&nbsp;(f, err, ...)</dt>
  469. <dd>
  470. This is a coroutine-safe drop-in replacement for Lua's "xpcall"-function
  471. <h3>Parameters</h3>
  472. <ul>
  473. <li>
  474. f: Lua function to be called protected
  475. </li>
  476. <li>
  477. err: Custom error handler
  478. </li>
  479. <li>
  480. ...: Parameters passed to the function
  481. </li>
  482. </ul>
  483. <h3>Return value:</h3>
  484. A boolean whether the function call succeeded and the return
  485. values of either the function or the error handler
  486. </dd>
  487. <dt><a name="dumptable"></a><strong>dumptable</strong>&nbsp;(t, maxdepth)</dt>
  488. <dd>
  489. Recursively dumps a table to stdout, useful for testing and debugging.
  490. <h3>Parameters</h3>
  491. <ul>
  492. <li>
  493. t: Table value to dump
  494. </li>
  495. <li>
  496. maxdepth: Maximum depth
  497. </li>
  498. </ul>
  499. <h3>Return value:</h3>
  500. Always nil
  501. </dd>
  502. <dt><a name="exec"></a><strong>exec</strong>&nbsp;(command)</dt>
  503. <dd>
  504. Execute given commandline and gather stdout.
  505. <h3>Parameters</h3>
  506. <ul>
  507. <li>
  508. command: String containing command to execute
  509. </li>
  510. </ul>
  511. <h3>Return value:</h3>
  512. String containing the command's stdout
  513. </dd>
  514. <dt><a name="execi"></a><strong>execi</strong>&nbsp;(command)</dt>
  515. <dd>
  516. Return a line-buffered iterator over the output of given command.
  517. <h3>Parameters</h3>
  518. <ul>
  519. <li>
  520. command: String containing the command to execute
  521. </li>
  522. </ul>
  523. <h3>Return value:</h3>
  524. Iterator
  525. </dd>
  526. <dt><a name="get_bytecode"></a><strong>get_bytecode</strong>&nbsp;(val)</dt>
  527. <dd>
  528. Return the current runtime bytecode of the given data. The byte code
  529. will be stripped before it is returned.
  530. <h3>Parameters</h3>
  531. <ul>
  532. <li>
  533. val: Value to return as bytecode
  534. </li>
  535. </ul>
  536. <h3>Return value:</h3>
  537. String value containing the bytecode of the given data
  538. </dd>
  539. <dt><a name="imatch"></a><strong>imatch</strong>&nbsp;(val)</dt>
  540. <dd>
  541. Return a matching iterator for the given value.
  542. The iterator will return one token per invocation, the tokens are separated by
  543. whitespace. If the input value is a table, it is transformed into a string first.
  544. A nil value will result in a valid iterator which aborts with the first invocation.
  545. <h3>Parameters</h3>
  546. <ul>
  547. <li>
  548. val: The value to scan (table, string or nil)
  549. </li>
  550. </ul>
  551. <h3>Return value:</h3>
  552. Iterator which returns one token per call
  553. </dd>
  554. <dt><a name="instanceof"></a><strong>instanceof</strong>&nbsp;(object, class)</dt>
  555. <dd>
  556. Test whether the given object is an instance of the given class.
  557. <h3>Parameters</h3>
  558. <ul>
  559. <li>
  560. object: Object instance
  561. </li>
  562. <li>
  563. class: Class object to test against
  564. </li>
  565. </ul>
  566. <h3>Return value:</h3>
  567. Boolean indicating whether the object is an instance
  568. <h3>See also:</h3>
  569. <ul>
  570. <li><a href="#class">
  571. class
  572. </a>
  573. <li><a href="#clone">
  574. clone
  575. </a>
  576. </ul>
  577. </dd>
  578. <dt><a name="keys"></a><strong>keys</strong>&nbsp;(t)</dt>
  579. <dd>
  580. Retrieve all keys of given associative table.
  581. <h3>Parameters</h3>
  582. <ul>
  583. <li>
  584. t: Table to extract keys from
  585. </li>
  586. </ul>
  587. <h3>Return value:</h3>
  588. Sorted table containing the keys
  589. </dd>
  590. <dt><a name="kspairs"></a><strong>kspairs</strong>&nbsp;(t)</dt>
  591. <dd>
  592. Return a key, value iterator for the given table.
  593. The table pairs are sorted by key.
  594. <h3>Parameters</h3>
  595. <ul>
  596. <li>
  597. t: The table to iterate
  598. </li>
  599. </ul>
  600. <h3>Return value:</h3>
  601. Function value containing the corresponding iterator
  602. </dd>
  603. <dt><a name="libpath"></a><strong>libpath</strong>&nbsp;()</dt>
  604. <dd>
  605. Returns the absolute path to LuCI base directory.
  606. <h3>Return value:</h3>
  607. String containing the directory path
  608. </dd>
  609. <dt><a name="parse_units"></a><strong>parse_units</strong>&nbsp;(ustr)</dt>
  610. <dd>
  611. Parse certain units from the given string and return the canonical integer
  612. value or 0 if the unit is unknown.
  613. Upper- or lower case is irrelevant.
  614. Recognized units are:
  615. o "y" - one year (60*60*24*366)
  616. o "m" - one month (60*60*24*31)
  617. o "w" - one week (60*60*24*7)
  618. o "d" - one day (60*60*24)
  619. o "h" - one hour (60*60)
  620. o "min" - one minute (60)
  621. o "kb" - one kilobyte (1024)
  622. o "mb" - one megabyte (1024*1024)
  623. o "gb" - one gigabyte (1024*1024*1024)
  624. o "kib" - one si kilobyte (1000)
  625. o "mib" - one si megabyte (1000*1000)
  626. o "gib" - one si gigabyte (1000*1000*1000)
  627. <h3>Parameters</h3>
  628. <ul>
  629. <li>
  630. ustr: String containing a numerical value with trailing unit
  631. </li>
  632. </ul>
  633. <h3>Return value:</h3>
  634. Number containing the canonical value
  635. </dd>
  636. <dt><a name="perror"></a><strong>perror</strong>&nbsp;(obj)</dt>
  637. <dd>
  638. Write given object to stderr.
  639. <h3>Parameters</h3>
  640. <ul>
  641. <li>
  642. obj: Value to write to stderr
  643. </li>
  644. </ul>
  645. <h3>Return value:</h3>
  646. Boolean indicating whether the write operation was successful
  647. </dd>
  648. <dt><a name="restore_data"></a><strong>restore_data</strong>&nbsp;(str)</dt>
  649. <dd>
  650. Restore data previously serialized with serialize_data().
  651. <h3>Parameters</h3>
  652. <ul>
  653. <li>
  654. str: String containing the data to restore
  655. </li>
  656. </ul>
  657. <h3>Return value:</h3>
  658. Value containing the restored data structure
  659. <h3>See also:</h3>
  660. <ul>
  661. <li><a href="#serialize_data">
  662. serialize_data
  663. </a>
  664. <li><a href="#get_bytecode">
  665. get_bytecode
  666. </a>
  667. </ul>
  668. </dd>
  669. <dt><a name="serialize_data"></a><strong>serialize_data</strong>&nbsp;(val)</dt>
  670. <dd>
  671. Recursively serialize given data to lua code, suitable for restoring
  672. with loadstring().
  673. <h3>Parameters</h3>
  674. <ul>
  675. <li>
  676. val: Value containing the data to serialize
  677. </li>
  678. </ul>
  679. <h3>Return value:</h3>
  680. String value containing the serialized code
  681. <h3>See also:</h3>
  682. <ul>
  683. <li><a href="#restore_data">
  684. restore_data
  685. </a>
  686. <li><a href="#get_bytecode">
  687. get_bytecode
  688. </a>
  689. </ul>
  690. </dd>
  691. <dt><a name="serialize_json"></a><strong>serialize_json</strong>&nbsp;(data, writer)</dt>
  692. <dd>
  693. Convert data structure to JSON
  694. <h3>Parameters</h3>
  695. <ul>
  696. <li>
  697. data: The data to serialize
  698. </li>
  699. <li>
  700. writer: A function to write a chunk of JSON data (optional)
  701. </li>
  702. </ul>
  703. <h3>Return value:</h3>
  704. String containing the JSON if called without write callback
  705. </dd>
  706. <dt><a name="shellquote"></a><strong>shellquote</strong>&nbsp;(value)</dt>
  707. <dd>
  708. Safely quote value for use in shell commands.
  709. <h3>Parameters</h3>
  710. <ul>
  711. <li>
  712. value: String containing the value to quote
  713. </li>
  714. </ul>
  715. <h3>Return value:</h3>
  716. Single-quote enclosed string with embedded quotes escaped
  717. </dd>
  718. <dt><a name="spairs"></a><strong>spairs</strong>&nbsp;(t, f)</dt>
  719. <dd>
  720. Return a key, value iterator which returns the values sorted according to
  721. the provided callback function.
  722. <h3>Parameters</h3>
  723. <ul>
  724. <li>
  725. t: The table to iterate
  726. </li>
  727. <li>
  728. f: A callback function to decide the order of elements
  729. </li>
  730. </ul>
  731. <h3>Return value:</h3>
  732. Function value containing the corresponding iterator
  733. </dd>
  734. <dt><a name="split"></a><strong>split</strong>&nbsp;(str, pat, max, regex)</dt>
  735. <dd>
  736. Splits given string on a defined separator sequence and return a table
  737. containing the resulting substrings.
  738. The optional max parameter specifies the number of bytes to process,
  739. regardless of the actual length of the given string. The optional last
  740. parameter, regex, specifies whether the separator sequence is
  741. nterpreted as regular expression.
  742. <h3>Parameters</h3>
  743. <ul>
  744. <li>
  745. str: String value containing the data to split up
  746. </li>
  747. <li>
  748. pat: String with separator pattern (optional, defaults to "\n")
  749. </li>
  750. <li>
  751. max: Maximum times to split (optional)
  752. </li>
  753. <li>
  754. regex: Boolean indicating whether to interpret the separator
  755. pattern as regular expression (optional, default is false)
  756. </li>
  757. </ul>
  758. <h3>Return value:</h3>
  759. Table containing the resulting substrings
  760. </dd>
  761. <dt><a name="strip_bytecode"></a><strong>strip_bytecode</strong>&nbsp;(code)</dt>
  762. <dd>
  763. Strips unnecessary lua bytecode from given string.
  764. Information like line numbers and debugging numbers will be discarded.
  765. Original version by Peter Cawley (http://lua-users.org/lists/lua-l/2008-02/msg01158.html)
  766. <h3>Parameters</h3>
  767. <ul>
  768. <li>
  769. code: String value containing the original lua byte code
  770. </li>
  771. </ul>
  772. <h3>Return value:</h3>
  773. String value containing the stripped lua byte code
  774. </dd>
  775. <dt><a name="threadlocal"></a><strong>threadlocal</strong>&nbsp;()</dt>
  776. <dd>
  777. Create a new or get an already existing thread local store associated with
  778. the current active coroutine.
  779. A thread local store is private a table object
  780. whose values can't be accessed from outside of the running coroutine.
  781. <h3>Return value:</h3>
  782. Table value representing the corresponding thread local store
  783. </dd>
  784. <dt><a name="trim"></a><strong>trim</strong>&nbsp;(str)</dt>
  785. <dd>
  786. Remove leading and trailing whitespace from given string value.
  787. <h3>Parameters</h3>
  788. <ul>
  789. <li>
  790. str: String value containing whitespace padded data
  791. </li>
  792. </ul>
  793. <h3>Return value:</h3>
  794. String value with leading and trailing space removed
  795. </dd>
  796. <dt><a name="ubus"></a><strong>ubus</strong>&nbsp;(object, method, values)</dt>
  797. <dd>
  798. Issue an ubus call.
  799. <h3>Parameters</h3>
  800. <ul>
  801. <li>
  802. object: String containing the ubus object to call
  803. </li>
  804. <li>
  805. method: String containing the ubus method to call
  806. </li>
  807. <li>
  808. values: Table containing the values to pass
  809. </li>
  810. </ul>
  811. <h3>Return value:</h3>
  812. Table containin the ubus result
  813. </dd>
  814. <dt><a name="update"></a><strong>update</strong>&nbsp;(t, updates)</dt>
  815. <dd>
  816. Update values in given table with the values from the second given table.
  817. Both table are - in fact - merged together.
  818. <h3>Parameters</h3>
  819. <ul>
  820. <li>
  821. t: Table which should be updated
  822. </li>
  823. <li>
  824. updates: Table containing the values to update
  825. </li>
  826. </ul>
  827. <h3>Return value:</h3>
  828. Always nil
  829. </dd>
  830. <dt><a name="urldecode"></a><strong>urldecode</strong>&nbsp;(str, decode_plus)</dt>
  831. <dd>
  832. Decode an URL-encoded string - optionally decoding the "+" sign to space.
  833. <h3>Parameters</h3>
  834. <ul>
  835. <li>
  836. str: Input string in x-www-urlencoded format
  837. </li>
  838. <li>
  839. decode_plus: Decode "+" signs to spaces if true (optional)
  840. </li>
  841. </ul>
  842. <h3>Return value:</h3>
  843. The decoded string
  844. <h3>See also:</h3>
  845. <ul>
  846. <li><a href="#urlencode">
  847. urlencode
  848. </a>
  849. </ul>
  850. </dd>
  851. <dt><a name="urlencode"></a><strong>urlencode</strong>&nbsp;(str)</dt>
  852. <dd>
  853. URL-encode given string.
  854. <h3>Parameters</h3>
  855. <ul>
  856. <li>
  857. str: String to encode
  858. </li>
  859. </ul>
  860. <h3>Return value:</h3>
  861. String containing the encoded data
  862. <h3>See also:</h3>
  863. <ul>
  864. <li><a href="#urldecode">
  865. urldecode
  866. </a>
  867. </ul>
  868. </dd>
  869. <dt><a name="vspairs"></a><strong>vspairs</strong>&nbsp;(t)</dt>
  870. <dd>
  871. Return a key, value iterator for the given table.
  872. The table pairs are sorted by value.
  873. <h3>Parameters</h3>
  874. <ul>
  875. <li>
  876. t: The table to iterate
  877. </li>
  878. </ul>
  879. <h3>Return value:</h3>
  880. Function value containing the corresponding iterator
  881. </dd>
  882. </dl>
  883. </div> <!-- id="content" -->
  884. </div> <!-- id="main" -->
  885. <div id="about">
  886. <p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p>
  887. </div> <!-- id="about" -->
  888. </div> <!-- id="container" -->
  889. </body>
  890. </html>