Permalink
Browse files

provider: Add support functions for calling external interpreters

This uses the provider module infrastructure to implement common code for
vimscript commands/functions that need to communicate with external
interpreters, eg: pydo, rubydo, pyfile, rubyfile, etc.
  • Loading branch information...
tarruda committed Jun 26, 2014
1 parent 887d32e commit 8a091e7f5c58a27fb3af1de76284430e812c95b5
Showing with 59 additions and 0 deletions.
  1. +18 −0 src/nvim/eval.c
  2. +41 −0 src/nvim/ex_cmds2.c
@@ -83,6 +83,7 @@
#include "nvim/os/time.h"
#include "nvim/os/channel.h"
#include "nvim/api/private/helpers.h"
#include "nvim/api/private/defs.h"
#include "nvim/os/msgpack_rpc_helpers.h"
#include "nvim/os/dl.h"
#include "nvim/os/provider.h"
@@ -19125,3 +19126,20 @@ static void apply_job_autocmds(Job *job, char *name, char *type, char *str)
apply_autocmds(EVENT_JOBACTIVITY, (uint8_t *)name, NULL, TRUE, NULL);
}

static void script_host_eval(char *method, typval_T *argvars, typval_T *rettv)
{
Object result = provider_call(method, vim_to_object(argvars));

if (result.type == kObjectTypeNil) {
return;
}

Error err = {.set = false};
object_to_vim(result, rettv, &err);
msgpack_rpc_free_object(result);

if (err.set) {
EMSG("Error converting value back to vim");
}
}

@@ -54,6 +54,10 @@
#include "nvim/os/os.h"
#include "nvim/os/shell.h"
#include "nvim/os/fs_defs.h"
#include "nvim/os/provider.h"
#include "nvim/os/msgpack_rpc_helpers.h"
#include "nvim/api/private/helpers.h"
#include "nvim/api/private/defs.h"


/* Growarray to store info about already sourced scripts.
@@ -3219,3 +3223,40 @@ char_u *get_locales(expand_T *xp, int idx)
}

#endif


static void script_host_execute(char *method, exarg_T *eap)
{
char *script = (char *)script_get(eap, eap->arg);

if (!eap->skip) {
String str = cstr_to_string(script ? script : (char *)eap->arg);
Object result = provider_call(method, STRING_OBJ(str));
// We don't care about the result, so free it just in case a bad provider
// returned something
msgpack_rpc_free_object(result);
}

free(script);
}

static void script_host_execute_file(char *method, exarg_T *eap)
{
char buffer[MAXPATHL];
vim_FullName(eap->arg, (uint8_t *)buffer, sizeof(buffer), false);

String file = cstr_to_string(buffer);
Object result = provider_call(method, STRING_OBJ(file));
msgpack_rpc_free_object(result);
}

static void script_host_do_range(char *method, exarg_T *eap)
{
Array arg = {0, 0, 0};
ADD(arg, INTEGER_OBJ(eap->line1));
ADD(arg, INTEGER_OBJ(eap->line2));
ADD(arg, STRING_OBJ(cstr_to_string((char *)eap->arg)));
Object result = provider_call(method, ARRAY_OBJ(arg));
msgpack_rpc_free_object(result);
}

0 comments on commit 8a091e7

Please sign in to comment.