make working classes && add vscode config && add lua submodule
This commit is contained in:
@@ -1,27 +1,30 @@
|
||||
#include "ARP_entry.h"
|
||||
#include "debug.h"
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/ksys.h>
|
||||
|
||||
|
||||
static int syscalls_gcARPEntry(lua_State *L)
|
||||
static int syscalls_gcARPEntry(lua_State* L)
|
||||
{
|
||||
free(lua_touserdata(L, 1));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool syscalls_cmpAPREntry(const struct ARP_entry *entry1, const struct ARP_entry *entry2)
|
||||
static bool syscalls_cmpAPREntry(const struct ARP_entry* entry1, const struct ARP_entry* entry2)
|
||||
{
|
||||
return memcmp(entry1, entry2, sizeof(struct ARP_entry));
|
||||
}
|
||||
|
||||
int syscalls_indexARPEntry(lua_State *L)
|
||||
int syscalls_indexARPEntry(lua_State* L)
|
||||
{
|
||||
struct ARP_entry *entry = (struct ARP_entry *)luaL_checkudata(L, 1, syscalls_ARPEntry_metatable_name);
|
||||
DEBUG_LINE("ARP entry index");
|
||||
|
||||
const char *index = luaL_checkstring(L, 2);
|
||||
struct ARP_entry* entry = (struct ARP_entry*)luaL_checkudata(L, 1, syscalls_ARPEntry_metatable_name);
|
||||
|
||||
const char* index = luaL_checkstring(L, 2);
|
||||
|
||||
if (strcmp(index, "IP") == 0)
|
||||
{
|
||||
@@ -50,11 +53,13 @@ int syscalls_indexARPEntry(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int syscalls_newindexARPEntry(lua_State *L)
|
||||
int syscalls_newindexARPEntry(lua_State* L)
|
||||
{
|
||||
struct ARP_entry *entry = (struct ARP_entry *)luaL_checkudata(L, 1, syscalls_ARPEntry_metatable_name);
|
||||
DEBUG_LINE("ARP entry newindex");
|
||||
|
||||
const char *index = luaL_checkstring(L, 2);
|
||||
struct ARP_entry* entry = (struct ARP_entry*)luaL_checkudata(L, 1, syscalls_ARPEntry_metatable_name);
|
||||
|
||||
const char* index = luaL_checkstring(L, 2);
|
||||
|
||||
if (strcmp(index, "IP"))
|
||||
{
|
||||
@@ -80,13 +85,13 @@ int syscalls_newindexARPEntry(lua_State *L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int syscalls_eqAPREntry(lua_State *L)
|
||||
static int syscalls_eqAPREntry(lua_State* L)
|
||||
{
|
||||
lua_pushboolean(
|
||||
L,
|
||||
L,
|
||||
syscalls_cmpAPREntry(
|
||||
(struct ARP_entry *)lua_touserdata(L, 1),
|
||||
(struct ARP_entry *)lua_touserdata(L, 2)
|
||||
(struct ARP_entry*)lua_touserdata(L, 1),
|
||||
(struct ARP_entry*)lua_touserdata(L, 2)
|
||||
)
|
||||
);
|
||||
|
||||
@@ -95,19 +100,15 @@ static int syscalls_eqAPREntry(lua_State *L)
|
||||
|
||||
|
||||
|
||||
int syscalls_newARPEntry(lua_State *L)
|
||||
int syscalls_newARPEntry(lua_State* L)
|
||||
{
|
||||
struct ARP_entry *entry = malloc(sizeof(struct ARP_entry));
|
||||
struct ARP_entry* entry = syscalls_pushARPEntry(L);;
|
||||
|
||||
entry->IP = luaL_checkinteger(L, 1);
|
||||
memcpy(entry->MAC, luaL_checkstring(L, 2), 6);
|
||||
entry->Status = luaL_checkinteger(L, 3);
|
||||
entry->TTL = luaL_checkinteger(L, 4);
|
||||
|
||||
syscalls_pushARPEntry(
|
||||
L,
|
||||
entry);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -116,27 +117,36 @@ static const luaL_Reg syscalls_ARPEntry_m[] = {
|
||||
{"__newindex", syscalls_newindexARPEntry},
|
||||
{"__eq", syscalls_eqAPREntry},
|
||||
{"__gc", syscalls_gcARPEntry},
|
||||
{NULL, NULL}};
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
void syscalls_pushARPEntry(lua_State* L, struct ARP_entry* entry)
|
||||
struct ARP_entry* syscalls_pushARPEntry(lua_State* L)
|
||||
{
|
||||
*(struct ARP_entry**)lua_newuserdata(L, sizeof(struct ARP_entry)) = entry;
|
||||
DEBUG_LINE("push ARP entry");
|
||||
|
||||
luaL_newlibtable(L, syscalls_ARPEntry_m);
|
||||
luaL_setfuncs(L, syscalls_ARPEntry_m, 0);
|
||||
struct ARP_entry* entry = lua_newuserdata(L, sizeof(struct ARP_entry));
|
||||
|
||||
lua_setmetatable(L, -2);
|
||||
luaL_setmetatable(L, syscalls_ARPEntry_metatable_name);
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
static const luaL_Reg syscalls_ARPEntry_lib[] = {
|
||||
{"new", syscalls_newARPEntry},
|
||||
{NULL, NULL}};
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
void syscalls_register_ARPEntry(lua_State *L)
|
||||
void syscalls_register_ARPEntry(lua_State* L)
|
||||
{
|
||||
DEBUG_LINE("register ARP entry");
|
||||
|
||||
luaL_newlib(L, syscalls_ARPEntry_lib);
|
||||
|
||||
lua_setfield(L, -2, syscalls_ARPEntry_name);
|
||||
|
||||
luaL_newlibtable(L, syscalls_ARPEntry_m);
|
||||
|
||||
luaL_newmetatable(L, syscalls_ARPEntry_metatable_name);
|
||||
luaL_setfuncs(L, syscalls_ARPEntry_m, 0);
|
||||
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user