Minetest 5.9.0-dev
 
Loading...
Searching...
No Matches
c_converter.h
Go to the documentation of this file.
1/*
2Minetest
3Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation; either version 2.1 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public License along
16with this program; if not, write to the Free Software Foundation, Inc.,
1751 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18*/
19
20
21/******************************************************************************/
22/******************************************************************************/
23/* WARNING!!!! do NOT add this header in any include file or any code file */
24/* not being a script/modapi file!!!!!!!! */
25/******************************************************************************/
26/******************************************************************************/
27#pragma once
28
29#include <vector>
30#include <string_view>
31
33#include "common/c_types.h"
34
35extern "C" {
36#include <lua.h>
37}
38
39std::string getstringfield_default(lua_State *L, int table,
40 const char *fieldname, const std::string &default_);
41bool getboolfield_default(lua_State *L, int table,
42 const char *fieldname, bool default_);
43float getfloatfield_default(lua_State *L, int table,
44 const char *fieldname, float default_);
45int getintfield_default(lua_State *L, int table,
46 const char *fieldname, int default_);
47
48bool check_field_or_nil(lua_State *L, int index, int type, const char *fieldname);
49
50template<typename T>
51bool getintfield(lua_State *L, int table,
52 const char *fieldname, T &result)
53{
54 lua_getfield(L, table, fieldname);
55 bool got = false;
56 if (check_field_or_nil(L, -1, LUA_TNUMBER, fieldname)){
57 result = lua_tointeger(L, -1);
58 got = true;
59 }
60 lua_pop(L, 1);
61 return got;
62}
63
64// Retrieve an v3s16 where all components are optional (falls back to default)
65v3s16 getv3s16field_default(lua_State *L, int table,
66 const char *fieldname, v3s16 default_);
67
68bool getstringfield(lua_State *L, int table,
69 const char *fieldname, std::string &result);
70bool getstringfield(lua_State *L, int table,
71 const char *fieldname, std::string_view &result);
72size_t getstringlistfield(lua_State *L, int table,
73 const char *fieldname,
74 std::vector<std::string> *result);
75bool getboolfield(lua_State *L, int table,
76 const char *fieldname, bool &result);
77bool getfloatfield(lua_State *L, int table,
78 const char *fieldname, float &result);
79
80void setstringfield(lua_State *L, int table,
81 const char *fieldname, const std::string &value);
82void setintfield(lua_State *L, int table,
83 const char *fieldname, int value);
84void setfloatfield(lua_State *L, int table,
85 const char *fieldname, float value);
86void setboolfield(lua_State *L, int table,
87 const char *fieldname, bool value);
88
89v3f checkFloatPos (lua_State *L, int index);
90v2f check_v2f (lua_State *L, int index);
91v3f check_v3f (lua_State *L, int index);
92v3s16 check_v3s16 (lua_State *L, int index);
93
94v3f read_v3f (lua_State *L, int index);
95v2f read_v2f (lua_State *L, int index);
96v2s16 read_v2s16 (lua_State *L, int index);
97v2s32 read_v2s32 (lua_State *L, int index);
98video::SColor read_ARGB8 (lua_State *L, int index);
99bool read_color (lua_State *L, int index,
100 video::SColor *color);
101bool is_color_table (lua_State *L, int index);
102
103aabb3f read_aabb3f (lua_State *L, int index, f32 scale);
104v3s16 read_v3s16 (lua_State *L, int index);
105std::vector<aabb3f> read_aabb3f_vector (lua_State *L, int index, f32 scale);
106size_t read_stringlist (lua_State *L, int index,
107 std::vector<std::string> *result);
108
109void push_v2s16 (lua_State *L, v2s16 p);
110void push_v2s32 (lua_State *L, v2s32 p);
111void push_v2u32 (lua_State *L, v2u32 p);
112void push_v3s16 (lua_State *L, v3s16 p);
113void push_aabb3f (lua_State *L, aabb3f box, f32 divisor = 1.0f);
114void push_ARGB8 (lua_State *L, video::SColor color);
115void pushFloatPos (lua_State *L, v3f p);
116void push_v3f (lua_State *L, v3f p);
117void push_v2f (lua_State *L, v2f p);
118void push_aabb3f_vector (lua_State *L, const std::vector<aabb3f> &boxes,
119 f32 divisor = 1.0f);
120
121void warn_if_field_exists(lua_State *L, int table,
122 const char *fieldname,
123 const std::string &message);
124
125size_t write_array_slice_float(lua_State *L, int table_index, float *data,
126 v3u16 data_size, v3u16 slice_offset, v3u16 slice_size);
127
128// This must match the implementation in builtin/game/misc_s.lua
129// Note that this returns a floating point result as Lua integers are 32-bit
130inline lua_Number hash_node_position(v3s16 pos)
131{
132 return (((s64)pos.Z + 0x8000L) << 32)
133 | (((s64)pos.Y + 0x8000L) << 16)
134 | ((s64)pos.X + 0x8000L);
135}
bool check_field_or_nil(lua_State *L, int index, int type, const char *fieldname)
Definition: c_converter.cpp:451
std::vector< aabb3f > read_aabb3f_vector(lua_State *L, int index, f32 scale)
Definition: c_converter.cpp:385
void push_ARGB8(lua_State *L, video::SColor color)
Definition: c_converter.cpp:230
int getintfield_default(lua_State *L, int table, const char *fieldname, int default_)
Definition: c_converter.cpp:561
size_t write_array_slice_float(lua_State *L, int table_index, float *data, v3u16 data_size, v3u16 slice_offset, v3u16 slice_size)
Definition: c_converter.cpp:633
size_t read_stringlist(lua_State *L, int index, std::vector< std::string > *result)
Definition: c_converter.cpp:423
bool is_color_table(lua_State *L, int index)
Definition: c_converter.cpp:319
size_t getstringlistfield(lua_State *L, int table, const char *fieldname, std::vector< std::string > *result)
Definition: c_converter.cpp:542
v2f check_v2f(lua_State *L, int index)
Definition: c_converter.cpp:167
void push_v2f(lua_State *L, v2f p)
Definition: c_converter.cpp:92
void push_v2s16(lua_State *L, v2s16 p)
Definition: c_converter.cpp:114
v3s16 check_v3s16(lua_State *L, int index)
Definition: c_converter.cpp:270
v3f checkFloatPos(lua_State *L, int index)
Definition: c_converter.cpp:249
v3f check_v3f(lua_State *L, int index)
Definition: c_converter.cpp:194
void warn_if_field_exists(lua_State *L, int table, const char *fieldname, const std::string &message)
Definition: c_content.cpp:1318
void pushFloatPos(lua_State *L, v3f p)
Definition: c_converter.cpp:243
bool getstringfield(lua_State *L, int table, const char *fieldname, std::string &result)
Definition: c_converter.cpp:485
bool read_color(lua_State *L, int index, video::SColor *color)
Definition: c_converter.cpp:277
void push_v3f(lua_State *L, v3f p)
Definition: c_converter.cpp:83
v2f read_v2f(lua_State *L, int index)
Definition: c_converter.cpp:154
bool getfloatfield(lua_State *L, int table, const char *fieldname, float &result)
Definition: c_converter.cpp:514
bool getintfield(lua_State *L, int table, const char *fieldname, T &result)
Definition: c_converter.h:51
float getfloatfield_default(lua_State *L, int table, const char *fieldname, float default_)
Definition: c_converter.cpp:569
void setintfield(lua_State *L, int table, const char *fieldname, int value)
Definition: c_converter.cpp:601
v2s32 read_v2s32(lua_State *L, int index)
Definition: c_converter.cpp:141
void setstringfield(lua_State *L, int table, const char *fieldname, const std::string &value)
Definition: c_converter.cpp:592
lua_Number hash_node_position(v3s16 pos)
Definition: c_converter.h:130
void push_aabb3f_vector(lua_State *L, const std::vector< aabb3f > &boxes, f32 divisor=1.0f)
Definition: c_converter.cpp:413
v3f read_v3f(lua_State *L, int index)
Definition: c_converter.cpp:184
v2s16 read_v2s16(lua_State *L, int index)
Definition: c_converter.cpp:101
std::string getstringfield_default(lua_State *L, int table, const char *fieldname, const std::string &default_)
Definition: c_converter.cpp:553
void push_v2s32(lua_State *L, v2s32 p)
Definition: c_converter.cpp:123
void push_v2u32(lua_State *L, v2u32 p)
Definition: c_converter.cpp:132
video::SColor read_ARGB8(lua_State *L, int index)
Definition: c_converter.cpp:296
bool getboolfield_default(lua_State *L, int table, const char *fieldname, bool default_)
Definition: c_converter.cpp:577
void setfloatfield(lua_State *L, int table, const char *fieldname, float value)
Definition: c_converter.cpp:610
aabb3f read_aabb3f(lua_State *L, int index, f32 scale)
Definition: c_converter.cpp:341
v3s16 getv3s16field_default(lua_State *L, int table, const char *fieldname, v3s16 default_)
Definition: c_converter.cpp:585
void push_v3s16(lua_State *L, v3s16 p)
Definition: c_converter.cpp:254
v3s16 read_v3s16(lua_State *L, int index)
Definition: c_converter.cpp:263
bool getboolfield(lua_State *L, int table, const char *fieldname, bool &result)
Definition: c_converter.cpp:528
void push_aabb3f(lua_State *L, aabb3f box, f32 divisor=1.0f)
Definition: c_converter.cpp:368
void setboolfield(lua_State *L, int table, const char *fieldname, bool value)
Definition: c_converter.cpp:619
core::aabbox3d< f32 > aabb3f
Definition: irr_aabb3d.h:26
core::vector2d< s32 > v2s32
Definition: irr_v2d.h:28
core::vector2d< s16 > v2s16
Definition: irr_v2d.h:27
core::vector2d< f32 > v2f
Definition: irr_v2d.h:26
core::vector2d< u32 > v2u32
Definition: irr_v2d.h:29
core::vector3d< u16 > v3u16
Definition: irr_v3d.h:29
core::vector3d< s16 > v3s16
Definition: irr_v3d.h:28
core::vector3df v3f
Definition: irr_v3d.h:26
static const struct table_key table[]
Definition: keycode.cpp:48
static std::string p(std::string path)
Definition: test_filesys.cpp:64