File: luaabstract.c

package info (click to toggle)
lua-cyrussasl 1.1.0-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 144 kB
  • sloc: ansic: 1,124; makefile: 30
file content (43 lines) | stat: -rw-r--r-- 870 bytes parent folder | download | duplicates (6)
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
#include <lua.h>
#include <stdio.h>

#include "luaabstract.h"

const char *tolstring(lua_State *l, int index, size_t *len)
{
  int type = lua_type(l, index);
  if (type != LUA_TSTRING) {
    char err[256];
    snprintf(err, sizeof(err),
	     "expected string, got %s",
	     lua_typename(l, type));
    lua_pushstring(l, err);
    lua_error(l);
    return NULL;
  }

  return lua_tolstring(l, index, len);
}

const char *tostring(lua_State *l, int index)
{
  if (lua_type(l, index) == LUA_TNIL)
    return NULL;

  return tolstring(l, index, NULL);
}

int tointeger(lua_State *l, int index)
{
  int type = lua_type(l, index);
  if (type != LUA_TNUMBER) {
    char err[256];
    snprintf(err, sizeof(err),
	     "expected integer, got %s",
	     lua_typename(l, type));
    lua_pushstring(l, err);
    lua_error(l);
    return 0;
  }
  return lua_tointeger(l, index);
}