Skip to content

Commit

Permalink
Document the limitations of lpc_ext_spawn().
Browse files Browse the repository at this point in the history
  • Loading branch information
dworkin committed May 21, 2024
1 parent bc7f347 commit aac234c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
4 changes: 4 additions & 0 deletions doc/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ Data can also be put directly into the input pipe, to be read back with
int lpc_ext_writeback(const void *buffer, int len);
```

This is intended for modules that offload some of their functionality into
an external program. It cannot be used to execute an arbitrary program and
communicate with it from LPC code.

## 6. Example

The following code implements a `lower_case()` kfun.
Expand Down
17 changes: 12 additions & 5 deletions src/lpc_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ DLLEXPORT int ext_init(int major, int minor, void **ftabs[], int sizes[],
in = out = back = INVALID_HANDLE_VALUE;

return (major == LPC_EXT_VERSION_MAJOR && minor >= LPC_EXT_VERSION_MINOR &&
ext_cb(ftabs[0], sizes[0], 6,
ext_cb(ftabs[0], sizes[0], 6,
&lpc_ext_kfun,
&lpc_ext_dbase,
&ext_spawn,
Expand Down Expand Up @@ -207,7 +207,12 @@ static void ext_finish(int wait)

/*
* NAME: lpc_ext->spawn()
* DESCRIPTION: spawn a child process and execute the given program
* DESCRIPTION: Spawn a child process and execute the given program. This
* is intended to be used by modules that offload some of their
* functionality in an external program, rather than as a way
* for LPC code to execute and communicate with such a program.
* The JIT compiler module uses this to run the LPC VM decompiler
* in isolation.
*/
int lpc_ext_spawn(const char *program)
{
Expand Down Expand Up @@ -327,7 +332,8 @@ int lpc_ext_spawn(const char *program)

/*
* NAME: lpc_ext->read()
* DESCRIPTION: read input from the child process
* DESCRIPTION: Read input from the child process. Not intended for use by
* LPC kfuns.
*/
int lpc_ext_read(void *buffer, int len)
{
Expand All @@ -336,7 +342,8 @@ int lpc_ext_read(void *buffer, int len)

/*
* NAME: lpc_ext->write()
* DESCRIPTION: write output to the child process
* DESCRIPTION: Write output to the child process. Not intended for use by
* LPC kfuns.
*/
int lpc_ext_write(const void *buffer, int len)
{
Expand All @@ -345,7 +352,7 @@ int lpc_ext_write(const void *buffer, int len)

/*
* NAME: lpc_ext->writeback()
* DESCRIPTION: write back to oneself
* DESCRIPTION: Write back to oneself. Not intended for use by LPC kfuns.
*/
int lpc_ext_writeback(const void *buffer, int len)
{
Expand Down

0 comments on commit aac234c

Please sign in to comment.