aboutsummaryrefslogtreecommitdiff
path: root/common.c
blob: c60c1ec3b0aaa0b499cc17dfdb7d8ff9e970e92e (plain) (blame)
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
#ifndef NERV_COMMON_H
#define NERV_COMMON_H
#include "common.h"
#include <stdarg.h>
int nerv_error(lua_State *L, const char *err_mesg_fmt, ...) {
    va_list ap;
    va_start(ap, err_mesg_fmt);
    lua_pushstring(L, "Nerv internal error: ");
    lua_pushvfstring(L, err_mesg_fmt, ap); 
    lua_concat(L, 2);
    lua_error(L);
    va_end(ap);
    return 0;
}

int nerv_error_method_not_implemented(lua_State *L) {
    return nerv_error(L, "method not implemented"); 
}

void luaN_append_methods(lua_State *L, const luaL_Reg *mlist) {
    for (; mlist->func; mlist++)
    {
        lua_pushcfunction(L, mlist->func);
        lua_setfield(L, -2, mlist->name);
    }
}
#endif