UFO: Alien Invasion
Loading...
Searching...
No Matches
scripts_lua.cpp
Go to the documentation of this file.
1
5
6/*
7Copyright (C) 2002-2025 UFO: Alien Invasion.
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18See the GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24*/
25
26#include "scripts_lua.h"
27#include "../shared/cxx.h"
28
29int Com_LuaIsNilOrTable (lua_State* L, int index) {
30 return (lua_isnil(L, index) || lua_istable(L, index));
31}
32
37 if (lua_isnil(L, index))
38 return nullptr;
39
40 linkedList_t* result = nullptr;
41 /* table is in the stack at 'index' */
42 lua_pushnil(L); /* first key */
43 while (lua_next(L, index) != 0) {
44 /* 'key' at index -2 and 'value' at index -1 */
45 const char* v = lua_tostring(L, -1);
46 if (v)
47 LIST_AddString(&result, v);
48 /* removes 'value', keeps 'key' for next iteration */
49 lua_pop(L, 1);
50 }
51 return result;
52}
void LIST_AddString(linkedList_t **listDest, const char *data)
Adds an string to a new or to an already existing linked list. The string is copied here.
Definition list.cpp:139
QGL_EXTERN int GLboolean GLfloat * v
Definition r_gl.h:120
QGL_EXTERN GLuint index
Definition r_gl.h:110
linkedList_t * Com_LuaTableToStringList(lua_State *L, int index)
Convert a lua table to a linkedList of character strings.
int Com_LuaIsNilOrTable(lua_State *L, int index)
Header for lua script functions.