summaryrefslogtreecommitdiff
path: root/src/lua5/cdluacairo5.c
blob: 0e99b3c6b3f63f50dea7290a1d27335fb72f885c (plain)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/** \file
 * \brief Cairo Lua 5 Binding
 *
 * See Copyright Notice in cd.h
 */

#include <stdlib.h>
#include <stdio.h>

#include "cd.h"
#include "cdcairo.h"

#include <lua.h>
#include <lauxlib.h>

#include "cdlua.h"
#include "cdlua5_private.h"


static void *cdimagergb_checkdata(lua_State* L, int param)
{
  return (void *)luaL_checkstring(L, param);
}

static cdluaContext cdluaimagergbctx = 
{
  0,
  "CAIRO_IMAGERGB",
  cdContextCairoImageRGB,
  cdimagergb_checkdata,
  NULL,
  0
};

static void *cdps_checkdata( lua_State *L, int param)
{
  return (void *)luaL_checkstring(L, param);
}

static cdluaContext cdluapsctx = 
{
  0,
  "CAIRO_PS",
  cdContextCairoPS,
  cdps_checkdata,
  NULL,
  0
};

static void *cdsvg_checkdata( lua_State *L, int param)
{
  return (void *)luaL_checkstring(L, param);
}

static cdluaContext cdluasvgctx = 
{
  0,
  "CAIRO_SVG",
  cdContextCairoSVG,
  cdsvg_checkdata,
  NULL,
  0
};

static void *cdpdf_checkdata(lua_State *L, int param)
{
  return (void *)luaL_checkstring(L, param);
}

static cdluaContext cdluapdfctx = 
{
  0,
  "CAIRO_PDF",
  cdContextCairoPDF,
  cdpdf_checkdata,
  NULL,
  0
};

static int cdlua5_initcairo(lua_State *L)
{
  (void)L;
  cdInitContextPlus();
  return 0;
}

static const struct luaL_reg cdlib[] = {
  {"InitContextPlus", cdlua5_initcairo},
  {NULL, NULL},
};


static int cdluacairo_open (lua_State *L)
{
  cdluaLuaState* cdL = cdlua_getstate(L);
  cdInitContextPlus();
  luaL_register(L, "cd", cdlib);   /* leave "cd" table at the top of the stack */
  cdlua_addcontext(L, cdL, &cdluapdfctx);
  cdlua_addcontext(L, cdL, &cdluapsctx);
  cdlua_addcontext(L, cdL, &cdluasvgctx);
  cdlua_addcontext(L, cdL, &cdluaimagergbctx);
  return 1;
}

int luaopen_cdluacairo(lua_State* L)
{
  return cdluacairo_open(L);
}