Extra file to keep luadgn.cc from growing even larger.
T7CCGLOZ25B7BQKKGR6IA6LWBRKUWTXLTIRXUQ4YKQRVAA7AHZKQC
ACZYEIX7WMPIIODKCATBCUE626AJ4ZGGBOMVC6BGXM27EQU2RECAC
MQ62OAMLGJVRW2QIL4PAZRAU6PC52ZVGY2FCOBIY6IWGQIHMU5CAC
AUXHSGS4EFOPZ6TVZYWNVOUDO7NYKUKE3HBKGQQWTALSVFOE3HAAC
Q2NUCKXB4P7DHRXY764F5AMEJO436GV74AVVVOAVGNWKLMSVMDNQC
7Y5HSDFKA5TPLS2TWTRFMQVX6UXUDHXU5MUMXQSDFAIY4THQ3BIQC
OYTCBRC7LE44EUVRZVYTOOVKQWJ6P6YE3FXTOGUTNKEMLNWPHKSQC
ED62QWGKBPORWVKDFOQRKJXEIWZVNGR3O4KWQBDSRNPT36AYOQYAC
NKONHW4JNY6HP2M63MNPM3H64ZWSUNUT5FX2STW4KTS4AMXJXXVQC
X7MFMKQTNZ2IWBFVGS6WQV7NRNKJ3DWQAW2X7IQMFQQXW24AHPZQC
ASLW3Z5PAVZSWJEMMMVZT226P44EKSAD47QS72JIFJESAI3RPN3AC
SM6YRPYZS6LMDQA6X3VAOK2PGMUFKPD7JMWJISOQSMX2CBR4ISPAC
UL7XFKMUX3WIU4O2LZANK4ECJ654UZPDBFGNXUEYZYOLKBYBCG6AC
void luaopen_setmeta(lua_State *ls,
const char *global,
const luaL_reg *lua_lib,
const char *meta);
#define LUAFN(name) static int name(lua_State *ls)
#define GETCOORD(c, p1, p2, boundfn) \
coord_def c; \
c.x = luaL_checkint(ls, p1); \
c.y = luaL_checkint(ls, p2); \
if (!boundfn(c)) \
luaL_error( \
ls, \
make_stringf("Point (%d,%d) is out of bounds", \
c.x, c.y).c_str()); \
else ;
#define COORDS(c, p1, p2) \
GETCOORD(c, p1, p2, in_bounds)
#define GETCOORD(c, p1, p2, boundfn) \
coord_def c; \
c.x = luaL_checkint(ls, p1); \
c.y = luaL_checkint(ls, p2); \
if (!boundfn(c)) \
luaL_error( \
ls, \
make_stringf("Point (%d,%d) is out of bounds", \
c.x, c.y).c_str()); \
else ; \
static void luaopen_setmeta(lua_State *ls,
const char *global,
const luaL_reg *lua_lib,
const char *meta)
void luaopen_setmeta(lua_State *ls,
const char *global,
const luaL_reg *lua_lib,
const char *meta)
/*
* File: l_los.h
* Summary: Lua bindings for LOS.
* Created by: Robert Vollmert
*/
#ifndef L_LOS_H
#define L_LOS_H
#include "clua.h"
extern const struct luaL_reg los_lib[];
void luaopen_ray(lua_State *ls);
#endif
/*
* File: l_los.cc
* Summary: Lua bindings for LOS.
* Created by: Robert Vollmert
*/
#include "AppHdr.h"
#include "l_los.h"
#include "los.h"
#include "luadgn.h"
#include "ray.h"
#define RAY_METATABLE "dgn.ray"
void lua_push_ray(lua_State *ls, ray_def *ray)
{
ray_def **rayref = clua_new_userdata<ray_def *>(ls, RAY_METATABLE);
*rayref = ray;
}
LUAFN(los_find_ray)
{
COORDS(a, 1, 2);
COORDS(b, 3, 4);
ray_def *ray = new ray_def;
if (find_ray(a, b, false, *ray, 0, true))
{
lua_push_ray(ls, ray);
return (1);
}
delete ray;
return (0);
}
const struct luaL_reg los_lib[] =
{
{ "findray", los_find_ray },
{ NULL, NULL }
};
#define RAY(ls, n, var) \
ray_def *var = *(ray_def **) luaL_checkudata(ls, n, RAY_METATABLE)
LUAFN(ray_accx)
{
RAY(ls, 1, ray);
lua_pushnumber(ls, ray->accx);
return (1);
}
LUAFN(ray_accy)
{
RAY(ls, 1, ray);
lua_pushnumber(ls, ray->accy);
return (1);
}
LUAFN(ray_slope)
{
RAY(ls, 1, ray);
lua_pushnumber(ls, ray->slope);
return (1);
}
LUAFN(ray_advance)
{
RAY(ls, 1, ray);
lua_pushnumber(ls, ray->advance());
return (1);
}
LUAFN(ray_pos)
{
RAY(ls, 1, ray);
coord_def p = ray->pos();
lua_pushnumber(ls, p.x);
lua_pushnumber(ls, p.y);
return (2);
}
static const struct luaL_reg ray_lib[] =
{
{ "accx", ray_accx },
{ "accy", ray_accy },
{ "slope", ray_slope },
{ "advance", ray_advance },
{ "pos", ray_pos },
{ NULL, NULL }
};
void luaopen_ray(lua_State *ls)
{
// luaopen_setmeta(ls, "ray", ray_lib, RAY_METATABLE);
clua_register_metatable(ls, RAY_METATABLE, ray_lib, lua_object_gc<ray_def>);
}