Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 5e810caac4
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 68 lines (53 sloc) 1.859 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
#ifndef ELUA_H
#define ELUA_H

#include <lualib.h>
#include "cstr.h"

// Configuration/options
typedef struct {
  // If enabled, comments in ELUA will not propagate to LUA. Default: 1
  char strip_comments;
  // If enabled, inputs a call to response.begin() before the first print statement is found. Default: 0
  char auto_begin_response_call;
} elua_conf_t;

// Context
typedef struct {
  cstr_t *buf;
  cstr_t *out;
  elua_conf_t *conf;
} elua_context_t;


// Initialize a new context.
// Also causes configuration to be initialized with default values, so no
// need to call elua_reset_conf, unless you want to reset the configuration.
void elua_init_context (elua_context_t *ctx);

// Free an initialized context
void elua_free_context (elua_context_t *ctx);

// Reset configuration with default values.
void elua_reset_conf (elua_conf_t *conf);


/**
* Parse from an open file.
*
* @param L The LUA stack/state
* @param f An open FD
* @param buf Temporary read buffer
* @param out Script buffer - this is where the final LUA-script will be after successful return.
* @param conf ELUA configuration
* @return Error code or 0 if no errors
*/
int elua_parse_file (lua_State *L, FILE *f, elua_context_t *ctx);

// Load a ELUA file
// Convenience function.
int elua_loadfile (lua_State *L, const char *fn, elua_context_t *ctx);


/**
* Load LUA-code from a cstr into the current state L.
*
* This is exactly like luaL_loadbuffer or luaL_loadstring, but loading from a
* cstr.
*
* @param L The LUA stack/state
* @param buf Code to load
* @param filename Name of the file being parsed. Prefix with '@' to get
* pretty error messages.
* @return Error code or 0 if no errors
*/
int lua_load_cstr (lua_State *L, cstr_t *buf, const char *filename);


#endif
Something went wrong with that request. Please try again.