Freeciv-3.3
Loading...
Searching...
No Matches
common
scriptcore
api_specenum.c
Go to the documentation of this file.
1
/*****************************************************************************
2
Freeciv - Copyright (C) 2010 - The Freeciv Project
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; either version 2, or (at your option)
6
any later version.
7
8
This program is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
GNU General Public License for more details.
12
*****************************************************************************/
13
14
#ifdef HAVE_CONFIG_H
15
#include <fc_config.h>
16
#endif
17
18
/* dependencies/lua */
19
#include "lua.h"
20
21
/* utilit */
22
#include "
log.h
"
23
24
#include "
api_specenum.h
"
25
26
/**********************************************************************/
29
void
api_specenum_create_table
(
lua_State
*
L
,
const
char
*
name
,
30
lua_CFunction
findex
)
31
{
32
/* Insert a module table in the global environment,
33
* or reuse any preexisting table */
34
lua_getglobal
(
L
,
name
);
35
if
(
lua_isnil
(
L
, -1)) {
36
lua_newtable
(
L
);
37
lua_pushvalue
(
L
, -1);
38
lua_setglobal
(
L
,
name
);
39
}
40
fc_assert_ret
(
lua_istable
(
L
, -1));
41
/* Create a metatable */
42
lua_newtable
(
L
);
/* stack: module mt */
43
lua_pushliteral
(
L
,
"__index"
);
44
lua_pushcfunction
(
L
,
findex
);
/* stack: module mt '__index' index */
45
lua_rawset
(
L
, -3);
/* stack: module mt */
46
lua_setmetatable
(
L
, -2);
/* stack: module */
47
lua_pop
(
L
, 1);
48
}
api_specenum_create_table
void api_specenum_create_table(lua_State *L, const char *name, lua_CFunction findex)
Definition
api_specenum.c:29
api_specenum.h
incite_cost
char * incite_cost
Definition
comments.c:76
name
const char * name
Definition
inputfile.c:127
log.h
fc_assert_ret
#define fc_assert_ret(condition)
Definition
log.h:192
Generated on Sun Dec 22 2024 22:30:37 for Freeciv-3.3 by
1.9.8