Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
148bd1ab4d |
No files matched your search
@@ -292,7 +292,6 @@ if(${SRB2_CONFIG_HAVE_BLUA})
|
||||
lua_script.c
|
||||
lua_skinlib.c
|
||||
lua_thinkerlib.c
|
||||
lua_udatalib.c
|
||||
lua_glib.c
|
||||
)
|
||||
set(SRB2_LUA_HEADERS
|
||||
@@ -302,7 +301,6 @@ if(${SRB2_CONFIG_HAVE_BLUA})
|
||||
lua_profile.h
|
||||
lua_libs.h
|
||||
lua_script.h
|
||||
lua_udatalib.h
|
||||
lua_glib.h
|
||||
)
|
||||
|
||||
|
||||
@@ -97,6 +97,5 @@ lua_playerlib.c
|
||||
lua_script.c
|
||||
lua_skinlib.c
|
||||
lua_thinkerlib.c
|
||||
lua_udatalib.c
|
||||
lua_glib.c
|
||||
lua_profile.cpp
|
||||
@@ -18,7 +18,6 @@
|
||||
#include "p_slopes.h"
|
||||
#include "r_main.h"
|
||||
|
||||
#include "lua_udatalib.h"
|
||||
#include "lua_script.h"
|
||||
#include "lua_libs.h"
|
||||
#include "lua_hud.h" // hud_running errors
|
||||
@@ -256,15 +255,6 @@ static const char *const vector_opt[] = {
|
||||
static const char *const array_opt[] ={"iterate",NULL};
|
||||
static const char *const valid_opt[] ={"valid",NULL};
|
||||
|
||||
#define pushsubsector(L, subsector) LUA_PushUserdata(L, subsector, META_SUBSECTOR)
|
||||
int udatalib_getter_subsector(lua_State *L)
|
||||
UDATALIB_SIMPLE_GETTER(subsector_t*, pushsubsector)
|
||||
#undef pushsubsector
|
||||
|
||||
#define pushslope(L, slope) LUA_PushUserdata(L, slope, META_SLOPE)
|
||||
int udatalib_getter_slope(lua_State *L)
|
||||
UDATALIB_SIMPLE_GETTER(pslope_t*, pushslope)
|
||||
#undef pushslope
|
||||
// iterates through a sector's thinglist!
|
||||
static int lib_iterateSectorThinglist(lua_State *L)
|
||||
{
|
||||
|
||||
+767
-734
File diff suppressed because it is too large.
Load diff
+847
-422
File diff suppressed because it is too large.
Load diff
@@ -1,137 +0,0 @@
|
||||
// SONIC ROBO BLAST 2 KART SATURN
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (C) 2025 by Indev.
|
||||
//
|
||||
// This program is free software distributed under the
|
||||
// terms of the GNU General Public License, version 2.
|
||||
// See the 'LICENSE' file for more details.
|
||||
//-----------------------------------------------------------------------------
|
||||
/// \file lua_udatalib.c
|
||||
/// \brief Implementation of lua userdata object metatables based on getter/setter functions
|
||||
|
||||
#include "doomtype.h"
|
||||
#include "m_fixed.h"
|
||||
#include "lua_udatalib.h"
|
||||
|
||||
// Getters
|
||||
int udatalib_getter_fixed(lua_State *L)
|
||||
UDATALIB_SIMPLE_GETTER(fixed_t, lua_pushinteger)
|
||||
|
||||
int udatalib_getter_angle(lua_State *L)
|
||||
UDATALIB_SIMPLE_GETTER(angle_t, lua_pushangle)
|
||||
|
||||
int udatalib_getter_uint8(lua_State *L)
|
||||
UDATALIB_SIMPLE_GETTER(UINT8, lua_pushinteger)
|
||||
|
||||
int udatalib_getter_sint8(lua_State *L)
|
||||
UDATALIB_SIMPLE_GETTER(SINT8, lua_pushinteger)
|
||||
|
||||
int udatalib_getter_uint16(lua_State *L)
|
||||
UDATALIB_SIMPLE_GETTER(UINT16, lua_pushinteger)
|
||||
|
||||
int udatalib_getter_int16(lua_State *L)
|
||||
UDATALIB_SIMPLE_GETTER(INT16, lua_pushinteger)
|
||||
|
||||
int udatalib_getter_uint32(lua_State *L)
|
||||
UDATALIB_SIMPLE_GETTER(UINT32, lua_pushinteger)
|
||||
|
||||
int udatalib_getter_int32(lua_State *L)
|
||||
UDATALIB_SIMPLE_GETTER(INT32, lua_pushinteger)
|
||||
|
||||
int udatalib_getter_uint64(lua_State *L)
|
||||
UDATALIB_SIMPLE_GETTER(UINT64, lua_pushinteger)
|
||||
|
||||
int udatalib_getter_int64(lua_State *L)
|
||||
UDATALIB_SIMPLE_GETTER(INT64, lua_pushinteger)
|
||||
|
||||
int udatalib_getter_string(lua_State *L)
|
||||
UDATALIB_SIMPLE_GETTER(const char*, lua_pushstring)
|
||||
|
||||
int udatalib_getter_boolean(lua_State *L)
|
||||
UDATALIB_SIMPLE_GETTER(boolean, lua_pushboolean)
|
||||
|
||||
int udatalib_getter_spritenum(lua_State *L)
|
||||
UDATALIB_SIMPLE_GETTER(spritenum_t, lua_pushinteger)
|
||||
|
||||
int udatalib_getter_tic(lua_State *L)
|
||||
UDATALIB_SIMPLE_GETTER(tic_t, lua_pushinteger)
|
||||
|
||||
// Setters
|
||||
int udatalib_setter_fixed(lua_State *L)
|
||||
UDATALIB_SIMPLE_SETTER(fixed_t, luaL_checkfixed)
|
||||
|
||||
int udatalib_setter_angle(lua_State *L)
|
||||
UDATALIB_SIMPLE_SETTER(angle_t, luaL_checkangle)
|
||||
|
||||
int udatalib_setter_uint8(lua_State *L)
|
||||
UDATALIB_SIMPLE_SETTER(UINT8, (UINT8)luaL_checkinteger)
|
||||
|
||||
int udatalib_setter_sint8(lua_State *L)
|
||||
UDATALIB_SIMPLE_SETTER(SINT8, luaL_checkinteger)
|
||||
|
||||
int udatalib_setter_uint16(lua_State *L)
|
||||
UDATALIB_SIMPLE_SETTER(UINT16, (UINT16)luaL_checkinteger)
|
||||
|
||||
int udatalib_setter_int16(lua_State *L)
|
||||
UDATALIB_SIMPLE_SETTER(INT16, luaL_checkinteger)
|
||||
|
||||
int udatalib_setter_uint32(lua_State *L)
|
||||
UDATALIB_SIMPLE_SETTER(UINT32, (UINT32)luaL_checkinteger)
|
||||
|
||||
int udatalib_setter_int32(lua_State *L)
|
||||
UDATALIB_SIMPLE_SETTER(INT32, luaL_checkinteger)
|
||||
|
||||
int udatalib_setter_uint64(lua_State *L)
|
||||
UDATALIB_SIMPLE_SETTER(UINT64, (UINT64)luaL_checkinteger)
|
||||
|
||||
int udatalib_setter_int64(lua_State *L)
|
||||
UDATALIB_SIMPLE_SETTER(INT64, luaL_checkinteger)
|
||||
|
||||
int udatalib_setter_string(lua_State *L)
|
||||
UDATALIB_SIMPLE_SETTER(const char*, luaL_checkstring)
|
||||
|
||||
int udatalib_setter_boolean(lua_State *L)
|
||||
UDATALIB_SIMPLE_SETTER(boolean, luaL_checkboolean)
|
||||
|
||||
// ffs
|
||||
int udatalib_setter_boolean_nocheck(lua_State *L)
|
||||
UDATALIB_SIMPLE_SETTER(boolean, lua_toboolean)
|
||||
|
||||
int udatalib_setter_spritenum(lua_State *L)
|
||||
UDATALIB_SIMPLE_SETTER(spritenum_t, luaL_checkinteger)
|
||||
|
||||
int udatalib_setter_tic(lua_State *L)
|
||||
UDATALIB_SIMPLE_SETTER(tic_t, (tic_t)luaL_checkinteger)
|
||||
|
||||
|
||||
void udatalib_addfield(lua_State *L, int mt, udata_field_t field)
|
||||
{
|
||||
int idx = abs_index(L, mt);
|
||||
|
||||
lua_createtable(L, 2, 0); // Push table
|
||||
|
||||
lua_pushinteger(L, field.offset); // Push offset
|
||||
lua_pushcclosure(L, field.getter, 1); // Pop offset, push closure
|
||||
|
||||
lua_rawseti(L, -2, UDATALIB_GETTER); // Pop closure, add to table
|
||||
|
||||
lua_pushinteger(L, field.offset); // Push offset
|
||||
lua_pushcclosure(L, field.setter, 1); // Pop offset, push closure
|
||||
|
||||
lua_rawseti(L, -2, UDATALIB_SETTER); // Pop closure, add to table
|
||||
|
||||
lua_pushstring(L, field.name); // Push field name
|
||||
lua_pushvalue(L, -2); // Copy table
|
||||
lua_rawset(L, idx); // Pop field name and table, add to metatable
|
||||
|
||||
lua_pop(L, 1); // Pop field table
|
||||
}
|
||||
|
||||
void udatalib_addfields(lua_State *L, int mt, const udata_field_t fields[])
|
||||
{
|
||||
for (unsigned i = 0; fields[i].name != NULL; ++i)
|
||||
{
|
||||
udatalib_addfield(L, mt, fields[i]);
|
||||
//CONS_Printf("Add field name=%s, offset=%d, getter=%p, setter=%p\n", fields[i].name, fields[i].offset, fields[i].getter, fields[i].setter);
|
||||
}
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
// SONIC ROBO BLAST 2 KART SATURN
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (C) 2025 by Indev.
|
||||
//
|
||||
// This program is free software distributed under the
|
||||
// terms of the GNU General Public License, version 2.
|
||||
// See the 'LICENSE' file for more details.
|
||||
//-----------------------------------------------------------------------------
|
||||
/// \file lua_udatalib.h
|
||||
/// \brief Implementation of lua userdata object metatables based on getter/setter functions
|
||||
|
||||
#ifndef __LUA_UDATALIB_H__
|
||||
#define __LUA_UDATALIB_H__
|
||||
|
||||
#include "doomdef.h"
|
||||
#include "lua_script.h"
|
||||
#include "lua_libs.h"
|
||||
#include "fastcmp.h"
|
||||
|
||||
// Indices in getter/setter tables for fields
|
||||
#define UDATALIB_GETTER 1
|
||||
#define UDATALIB_SETTER 2
|
||||
|
||||
typedef struct udata_field_s {
|
||||
const char *name;
|
||||
size_t offset;
|
||||
lua_CFunction getter;
|
||||
lua_CFunction setter;
|
||||
} udata_field_t;
|
||||
|
||||
// Simple setters and getters, for situations where getter is simply
|
||||
// "return obj.field" and setter is "obj.field = value"
|
||||
int udatalib_getter_fixed(lua_State *L);
|
||||
int udatalib_getter_angle(lua_State *L);
|
||||
int udatalib_getter_uint8(lua_State *L);
|
||||
int udatalib_getter_sint8(lua_State *L);
|
||||
int udatalib_getter_uint16(lua_State *L);
|
||||
int udatalib_getter_int16(lua_State *L);
|
||||
int udatalib_getter_uint32(lua_State *L);
|
||||
int udatalib_getter_int32(lua_State *L);
|
||||
int udatalib_getter_uint64(lua_State *L);
|
||||
int udatalib_getter_int64(lua_State *L);
|
||||
int udatalib_getter_string(lua_State *L);
|
||||
int udatalib_getter_boolean(lua_State *L);
|
||||
int udatalib_getter_spritenum(lua_State *L);
|
||||
int udatalib_getter_mobj(lua_State *L);
|
||||
int udatalib_getter_subsector(lua_State *L);
|
||||
int udatalib_getter_mobjtype(lua_State *L);
|
||||
int udatalib_getter_player(lua_State *L);
|
||||
int udatalib_getter_mapthing(lua_State *L);
|
||||
int udatalib_getter_slope(lua_State *L);
|
||||
int udatalib_getter_cmd(lua_State *L);
|
||||
int udatalib_getter_playerstate(lua_State *L);
|
||||
int udatalib_getter_powers(lua_State *L);
|
||||
int udatalib_getter_kartstuff(lua_State *L);
|
||||
int udatalib_getter_pflags(lua_State *L);
|
||||
int udatalib_getter_panim(lua_State *L);
|
||||
int udatalib_getter_tic(lua_State *L);
|
||||
|
||||
int udatalib_setter_fixed(lua_State *L);
|
||||
int udatalib_setter_angle(lua_State *L);
|
||||
int udatalib_setter_uint8(lua_State *L);
|
||||
int udatalib_setter_sint8(lua_State *L);
|
||||
int udatalib_setter_uint16(lua_State *L);
|
||||
int udatalib_setter_int16(lua_State *L);
|
||||
int udatalib_setter_uint32(lua_State *L);
|
||||
int udatalib_setter_int32(lua_State *L);
|
||||
int udatalib_setter_uint64(lua_State *L);
|
||||
int udatalib_setter_int64(lua_State *L);
|
||||
int udatalib_setter_string(lua_State *L);
|
||||
int udatalib_setter_boolean(lua_State *L);
|
||||
int udatalib_setter_boolean_nocheck(lua_State *L);
|
||||
int udatalib_setter_spritenum(lua_State *L);
|
||||
int udatalib_setter_mobj(lua_State *L);
|
||||
int udatalib_setter_playerstate(lua_State *L);
|
||||
int udatalib_setter_pflags(lua_State *L);
|
||||
int udatalib_setter_panim(lua_State *L);
|
||||
int udatalib_setter_tic(lua_State *L);
|
||||
|
||||
// Adds setter and getter for field and stores it as field.name..".get" and
|
||||
// field.name..".set" in table at index mt. (metatable, usually)
|
||||
void udatalib_addfield(lua_State *L, int mt, udata_field_t field);
|
||||
|
||||
// Convinience function to add array of fields at once.
|
||||
void udatalib_addfields(lua_State *L, int mt, const udata_field_t fields[]);
|
||||
|
||||
// I miss C++ template functons :(
|
||||
|
||||
// Get pointer to field value within getter or setter
|
||||
#define UDATALIB_GETFIELD(type, field) \
|
||||
{ \
|
||||
size_t offset = lua_tointeger(L, lua_upvalueindex(1)); \
|
||||
field = (type*)((uint8_t*)lua_touserdata(L, 1) + offset); \
|
||||
}
|
||||
|
||||
// Creates implementation for simple getter and setter. Super lazy, yes.
|
||||
// Assumes userdata is a pointer to actual data. Maybe not really safe.
|
||||
#define UDATALIB_SIMPLE_GETTER(type, pushf) \
|
||||
{ \
|
||||
type *field; \
|
||||
UDATALIB_GETFIELD(type, field) \
|
||||
pushf(L, *field); \
|
||||
return 1; \
|
||||
}
|
||||
|
||||
#define UDATALIB_SIMPLE_SETTER(type, checkf) \
|
||||
{ \
|
||||
type *field; \
|
||||
UDATALIB_GETFIELD(type, field) \
|
||||
*field = checkf(L, 2); \
|
||||
return 0; \
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user