MCPcopy Create free account
hub / github.com/crawl/crawl / _execute_embedded_lua

Function _execute_embedded_lua

crawl-ref/source/database.cc:434–466  ·  view source on GitHub ↗

////////////////////////////////////////////////////////////////////// Internal DB utility functions

Source from the content-addressed store, hash-verified

432///////////////////////////////////////////////////////////////////////////
433// Internal DB utility functions
434static 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
468static void _substitute_descriptions(TextDB &db, string &str,
469 bool canonicalise_key, bool run_lua,

Callers 3

_query_databaseFunction · 0.85
getSpeakStringFunction · 0.85
getMiscStringFunction · 0.85

Calls 6

mprfFunction · 0.85
substrMethod · 0.80
execstringMethod · 0.80
replaceMethod · 0.80
fnreturnsMethod · 0.80
findMethod · 0.45

Tested by

no test coverage detected