ex_getln: Refactor script_get()

1. Use `char *` for strings.
2. Add `const` qualifiers.
3. Add attributes and documentation.
4. Handle skipping *inside*.
5. Handle non-heredoc argument also inside: deferring this to the caller is
   pointless because all callers need the same thing. Though new ex_lua caller
   may live without allocations in this case, allocating nevertheless produces
   cleaner code.
6. Note that all callers call script_get with `eap` and `eap->arg`. Thus second
   argument is useless in practice: it is one and the same always and can be
   reached through the first argument.
This commit is contained in:
ZyX
2017-01-29 03:36:47 +03:00
parent 3531d8c8ea
commit 3d48c35d6b
4 changed files with 58 additions and 38 deletions

View File

@@ -277,9 +277,14 @@ void executor_eval_lua(const String str, typval_T *const arg,
void ex_lua(exarg_T *const eap)
FUNC_ATTR_NONNULL_ALL
{
char *const code = (char *)script_get(eap, eap->arg);
size_t len;
char *const code = script_get(eap, &len);
if (eap->skip) {
xfree(code);
return;
}
typval_T tv = { .v_type = VAR_UNKNOWN };
executor_exec_lua(cstr_as_string(code), &tv);
executor_exec_lua((String) { .data = code, .size = len }, &tv);
clear_tv(&tv);
xfree(code);
}