////////////////////////////////////////////////////////////////////// Internal DB utility functions
| 432 | /////////////////////////////////////////////////////////////////////////// |
| 433 | // Internal DB utility functions |
| 434 | static void _execute_embedded_lua(string &str) |
| 435 | { |
| 436 | // Execute any lua code found between "{{" and "}}". The lua code |
| 437 | // is expected to return a string, with which the lua code and |
| 438 | // braces will be replaced. |
| 439 | string::size_type pos = str.find("{{"); |
| 440 | while (pos != string::npos) |
| 441 | { |
| 442 | string::size_type end = str.find("}}", pos + 2); |
| 443 | if (end == string::npos) |
| 444 | { |
| 445 | mprf(MSGCH_DIAGNOSTICS, "Unbalanced {{, bailing."); |
| 446 | break; |
| 447 | } |
| 448 | |
| 449 | string lua_full = str.substr(pos, end - pos + 2); |
| 450 | string lua = str.substr(pos + 2, end - pos - 2); |
| 451 | |
| 452 | if (clua.execstring(lua.c_str(), "db_embedded_lua", 1)) |
| 453 | { |
| 454 | string err = "{{" + clua.error + "}}"; |
| 455 | str.replace(pos, lua_full.length(), err); |
| 456 | return; |
| 457 | } |
| 458 | |
| 459 | string result; |
| 460 | clua.fnreturns(">s", &result); |
| 461 | |
| 462 | str.replace(pos, lua_full.length(), result); |
| 463 | |
| 464 | pos = str.find("{{", pos + result.length()); |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | static void _substitute_descriptions(TextDB &db, string &str, |
| 469 | bool canonicalise_key, bool run_lua, |