1
0

luci.util.html 24 KB

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