add lua funcs names to Spell words && use tabs instead spaces

This commit is contained in:
2025-04-05 17:49:35 +05:00
parent 273e9edfc7
commit 5dc9f2ca31
11 changed files with 1586 additions and 1558 deletions

31
.vscode/settings.json vendored
View File

@@ -1,5 +1,34 @@
{ {
"editor.tabSize": 4,
"editor.insertSpaces": false,
"files.associations": { "files.associations": {
"stdlib.h": "c" "stdlib.h": "c"
} },
"cSpell.words": [
"ksys",
"ksys_oskey_t",
"LUALIB_API",
"luaL_newlib",
"metatable",
"luaL_newmetatable",
"luaL_setmetatable",
"lua_createtable",
"luaL_setfuncs",
"luaL_checkinteger",
"luaL_checkstring",
"luaL_checkudata",
"lua_pushboolean",
"lua_pushinteger",
"lua_pushnumber",
"luaL_optinteger",
"lua_pushstring",
"lua_pushnil",
"lua_touserdata",
"lua_setfield",
"lua_getfield",
"lua_settop",
"lua_islightuserdata",
"luaL_checktype",
"LUA_TTABLE",
]
} }

View File

@@ -1,3 +1,3 @@
# syscalls # Syscalls
syscalls for Lua Syscalls library for Lua

View File

@@ -8,145 +8,145 @@
static int syscalls_gcARPEntry(lua_State* L) static int syscalls_gcARPEntry(lua_State* L)
{ {
free(lua_touserdata(L, 1)); free(lua_touserdata(L, 1));
return 0; 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)); return memcmp(entry1, entry2, sizeof(struct ARP_entry));
} }
int syscalls_indexARPEntry(lua_State* L) int syscalls_indexARPEntry(lua_State* L)
{ {
DEBUG_LINE("ARP entry index"); DEBUG_LINE("ARP entry index");
struct ARP_entry* entry = (struct ARP_entry*)luaL_checkudata(L, 1, syscalls_ARPEntry_metatable_name); struct ARP_entry* entry = (struct ARP_entry*)luaL_checkudata(L, 1, syscalls_ARPEntry_metatable_name);
const char* index = luaL_checkstring(L, 2); const char* index = luaL_checkstring(L, 2);
if (strcmp(index, "IP") == 0) if (strcmp(index, "IP") == 0)
{ {
lua_pushinteger(L, entry->IP); lua_pushinteger(L, entry->IP);
} }
else if (strcmp(index, "MAC") == 0) else if (strcmp(index, "MAC") == 0)
{ {
char str[7]; char str[7];
memset(str, entry->MAC, 6); memset(str, entry->MAC, 6);
str[6] = '\n'; str[6] = '\n';
lua_pushstring(L, str); lua_pushstring(L, str);
} }
else if (strcmp(index, "Status") == 0) else if (strcmp(index, "Status") == 0)
{ {
lua_pushinteger(L, entry->Status); lua_pushinteger(L, entry->Status);
} }
else if (strcmp(index, "TTL") == 0) else if (strcmp(index, "TTL") == 0)
{ {
lua_pushinteger(L, entry->TTL); lua_pushinteger(L, entry->TTL);
} }
else else
{ {
_ksys_debug_puts("err\n"); _ksys_debug_puts("err\n");
} }
return 1; return 1;
} }
int syscalls_newindexARPEntry(lua_State* L) int syscalls_newindexARPEntry(lua_State* L)
{ {
DEBUG_LINE("ARP entry newindex"); DEBUG_LINE("ARP entry newindex");
struct ARP_entry* entry = (struct ARP_entry*)luaL_checkudata(L, 1, syscalls_ARPEntry_metatable_name); struct ARP_entry* entry = (struct ARP_entry*)luaL_checkudata(L, 1, syscalls_ARPEntry_metatable_name);
const char* index = luaL_checkstring(L, 2); const char* index = luaL_checkstring(L, 2);
if (strcmp(index, "IP")) if (strcmp(index, "IP"))
{ {
entry->IP = luaL_checkinteger(L, 3); entry->IP = luaL_checkinteger(L, 3);
} }
else if (strcmp(index, "MAC")) else if (strcmp(index, "MAC"))
{ {
memset(entry->MAC, luaL_checkstring(L, 3), 6); memset(entry->MAC, luaL_checkstring(L, 3), 6);
} }
else if (strcmp(index, "Status")) else if (strcmp(index, "Status"))
{ {
entry->Status = luaL_checkinteger(L, 3); entry->Status = luaL_checkinteger(L, 3);
} }
else if (strcmp(index, "TTL")) else if (strcmp(index, "TTL"))
{ {
entry->TTL = luaL_checkinteger(L, 3); entry->TTL = luaL_checkinteger(L, 3);
} }
else else
{ {
_ksys_debug_puts("err\n"); _ksys_debug_puts("err\n");
} }
return 0; return 0;
} }
static int syscalls_eqAPREntry(lua_State* L) static int syscalls_eqAPREntry(lua_State* L)
{ {
lua_pushboolean( lua_pushboolean(
L, L,
syscalls_cmpAPREntry( syscalls_cmpAPREntry(
(struct ARP_entry*)lua_touserdata(L, 1), (struct ARP_entry*)lua_touserdata(L, 1),
(struct ARP_entry*)lua_touserdata(L, 2) (struct ARP_entry*)lua_touserdata(L, 2)
) )
); );
return 1; return 1;
} }
int syscalls_newARPEntry(lua_State* L) int syscalls_newARPEntry(lua_State* L)
{ {
struct ARP_entry* entry = syscalls_pushARPEntry(L);; struct ARP_entry* entry = syscalls_pushARPEntry(L);;
entry->IP = luaL_checkinteger(L, 1); entry->IP = luaL_checkinteger(L, 1);
memcpy(entry->MAC, luaL_checkstring(L, 2), 6); memcpy(entry->MAC, luaL_checkstring(L, 2), 6);
entry->Status = luaL_checkinteger(L, 3); entry->Status = luaL_checkinteger(L, 3);
entry->TTL = luaL_checkinteger(L, 4); entry->TTL = luaL_checkinteger(L, 4);
return 1; return 1;
} }
static const luaL_Reg syscalls_ARPEntry_m[] = { static const luaL_Reg syscalls_ARPEntry_m[] = {
{"__index", syscalls_indexARPEntry}, {"__index", syscalls_indexARPEntry},
{"__newindex", syscalls_newindexARPEntry}, {"__newindex", syscalls_newindexARPEntry},
{"__eq", syscalls_eqAPREntry}, {"__eq", syscalls_eqAPREntry},
{"__gc", syscalls_gcARPEntry}, {"__gc", syscalls_gcARPEntry},
{NULL, NULL} {NULL, NULL}
}; };
struct ARP_entry* syscalls_pushARPEntry(lua_State* L) struct ARP_entry* syscalls_pushARPEntry(lua_State* L)
{ {
DEBUG_LINE("push ARP entry"); DEBUG_LINE("push ARP entry");
struct ARP_entry* entry = lua_newuserdata(L, sizeof(struct ARP_entry)); struct ARP_entry* entry = lua_newuserdata(L, sizeof(struct ARP_entry));
luaL_setmetatable(L, syscalls_ARPEntry_metatable_name); luaL_setmetatable(L, syscalls_ARPEntry_metatable_name);
return entry; return entry;
} }
static const luaL_Reg syscalls_ARPEntry_lib[] = { static const luaL_Reg syscalls_ARPEntry_lib[] = {
{"new", syscalls_newARPEntry}, {"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"); DEBUG_LINE("register ARP entry");
luaL_newlib(L, syscalls_ARPEntry_lib); luaL_newlib(L, syscalls_ARPEntry_lib);
lua_setfield(L, -2, syscalls_ARPEntry_name); lua_setfield(L, -2, syscalls_ARPEntry_name);
luaL_newmetatable(L, syscalls_ARPEntry_metatable_name); luaL_newmetatable(L, syscalls_ARPEntry_metatable_name);
luaL_setfuncs(L, syscalls_ARPEntry_m, 0); luaL_setfuncs(L, syscalls_ARPEntry_m, 0);
lua_pop(L, 1); lua_pop(L, 1);
} }

View File

@@ -1,19 +1,18 @@
#ifndef _SYSCALLS_ARP_ENTRY_ #ifndef __SYSCALLS_ARP_ENTRY__
#define _SYSCALLS_ARP_ENTRY #define __SYSCALLS_ARP_ENTRY__
#include <lua.h> #include <lua.h>
#include <lualib.h> #include <lualib.h>
#include <lauxlib.h> #include <lauxlib.h>
#include <stdint.h> #include <stdint.h>
struct ARP_entry struct ARP_entry
{ {
uint32_t IP; uint32_t IP;
char MAC[6]; char MAC[6];
uint16_t Status; uint16_t Status;
uint16_t TTL; uint16_t TTL;
}; };
#define syscalls_ARPEntry_name "ARPEntry" #define syscalls_ARPEntry_name "ARPEntry"
@@ -33,4 +32,4 @@ int syscalls_newindexARPEntry(lua_State* L);
void syscalls_register_ARPEntry(lua_State* L); void syscalls_register_ARPEntry(lua_State* L);
#endif #endif // __SYSCALLS_ARP_ENTRY__

View File

@@ -4,10 +4,11 @@
#ifdef NDEBUG #ifdef NDEBUG
#include <sys/ksys.h> #include <sys/ksys.h>
/** /**
* Debug out, enabled * Debug out, enabled
*/ */
#define DEBUG_PRINT(msg) _ksys_debug_puts(msg) #define DEBUG_PRINT(msg) _ksys_debug_puts(msg)
#else #else
@@ -18,6 +19,6 @@
#endif #endif
#define DEBUG_LINE(msg) DEBUG_PRINT(msg); DEBUG_PRINT("\n") #define DEBUG_LINE(msg) DEBUG_PRINT(msg); DEBUG_PRINT("\n")
#endif // __DEBUG_H__ #endif // __DEBUG_H__

View File

@@ -6,7 +6,7 @@
#include <lauxlib.h> #include <lauxlib.h>
#include <sys/ksys.h> #include <sys/ksys.h>
static inline void syscalls_register_scancodes(lua_State *L) static inline void syscalls_register_scancodes(lua_State* L)
{ {
lua_newtable(L); lua_newtable(L);

File diff suppressed because it is too large Load Diff

View File

@@ -8,187 +8,187 @@ static int syscalls_SystemColors_m_index;
int syscalls_newSystemColors(lua_State* L) int syscalls_newSystemColors(lua_State* L)
{ {
ksys_colors_table_t* colorsTable = syscalls_pushSystemColors(L); ksys_colors_table_t* colorsTable = syscalls_pushSystemColors(L);
colorsTable->frame_area = luaL_optinteger(L, 1, 0); colorsTable->frame_area = luaL_optinteger(L, 1, 0);
colorsTable->grab_bar = luaL_optinteger(L, 2, 0); colorsTable->grab_bar = luaL_optinteger(L, 2, 0);
colorsTable->grab_bar_button = luaL_optinteger(L, 3, 0); colorsTable->grab_bar_button = luaL_optinteger(L, 3, 0);
colorsTable->grab_button_text = luaL_optinteger(L, 4, 0); colorsTable->grab_button_text = luaL_optinteger(L, 4, 0);
colorsTable->grab_text = luaL_optinteger(L, 5, 0); colorsTable->grab_text = luaL_optinteger(L, 5, 0);
colorsTable->work_area = luaL_optinteger(L, 6, 0); colorsTable->work_area = luaL_optinteger(L, 6, 0);
colorsTable->work_button = luaL_optinteger(L, 7, 0); colorsTable->work_button = luaL_optinteger(L, 7, 0);
colorsTable->work_button_text = luaL_optinteger(L, 8, 0); colorsTable->work_button_text = luaL_optinteger(L, 8, 0);
colorsTable->work_graph = luaL_optinteger(L, 9, 0); colorsTable->work_graph = luaL_optinteger(L, 9, 0);
colorsTable->work_text = luaL_optinteger(L, 10, 0); colorsTable->work_text = luaL_optinteger(L, 10, 0);
return 1; return 1;
} }
static int syscalls_indexSystemColors(lua_State* L) static int syscalls_indexSystemColors(lua_State* L)
{ {
DEBUG_LINE("system colors index"); DEBUG_LINE("system colors index");
const ksys_colors_table_t* t = (const ksys_colors_table_t*)luaL_checkudata(L, 1, syscalls_SystemColors_metatable_name); const ksys_colors_table_t* t = (const ksys_colors_table_t*)luaL_checkudata(L, 1, syscalls_SystemColors_metatable_name);
const char* index = luaL_checkstring(L, 2); const char* index = luaL_checkstring(L, 2);
if (strcmp("frameArea", index) == 0) if (strcmp("frameArea", index) == 0)
{ {
lua_pushinteger(L, t->frame_area); lua_pushinteger(L, t->frame_area);
} }
else if (strcmp("grabBar", index) == 0) else if (strcmp("grabBar", index) == 0)
{ {
lua_pushinteger(L, t->grab_bar); lua_pushinteger(L, t->grab_bar);
} }
else if (strcmp("grabBarButton", index) == 0) else if (strcmp("grabBarButton", index) == 0)
{ {
lua_pushinteger(L, t->grab_bar_button); lua_pushinteger(L, t->grab_bar_button);
} }
else if (strcmp("grab_button_text", index) == 0) else if (strcmp("grab_button_text", index) == 0)
{ {
lua_pushinteger(L, t->grab_button_text); lua_pushinteger(L, t->grab_button_text);
} }
else if (strcmp("grabText", index) == 0) else if (strcmp("grabText", index) == 0)
{ {
lua_pushinteger(L, t->grab_text); lua_pushinteger(L, t->grab_text);
} }
else if (strcmp("workArea", index) == 0) else if (strcmp("workArea", index) == 0)
{ {
lua_pushinteger(L, t->work_area); lua_pushinteger(L, t->work_area);
} }
else if (strcmp("workButton", index) == 0) else if (strcmp("workButton", index) == 0)
{ {
lua_pushinteger(L, t->work_button); lua_pushinteger(L, t->work_button);
} }
else if (strcmp("workButtonText", index) == 0) else if (strcmp("workButtonText", index) == 0)
{ {
lua_pushinteger(L, t->work_button_text); lua_pushinteger(L, t->work_button_text);
} }
else if (strcmp("workGraph", index) == 0) else if (strcmp("workGraph", index) == 0)
{ {
lua_pushinteger(L, t->work_graph); lua_pushinteger(L, t->work_graph);
} }
else if (strcmp("workText", index) == 0) else if (strcmp("workText", index) == 0)
{ {
lua_pushinteger(L, t->work_text); lua_pushinteger(L, t->work_text);
} }
else else
{ {
luaL_error(L, "wrong index: %s", index); luaL_error(L, "wrong index: %s", index);
} }
return 1; return 1;
} }
static int syscalls_newindexSystemColors(lua_State* L) static int syscalls_newindexSystemColors(lua_State* L)
{ {
ksys_colors_table_t* t = luaL_checkudata(L, 1, syscalls_SystemColors_metatable_name); ksys_colors_table_t* t = luaL_checkudata(L, 1, syscalls_SystemColors_metatable_name);
const char* index = luaL_checkstring(L, 2); const char* index = luaL_checkstring(L, 2);
LUA_INTEGER val = luaL_checkinteger(L, 3); ksys_color_t val = luaL_checkinteger(L, 3);
if (strcmp("frameArea", index) == 0) if (strcmp("frameArea", index) == 0)
{ {
t->frame_area = val; t->frame_area = val;
} }
else if (strcmp("grabBar", index) == 0) else if (strcmp("grabBar", index) == 0)
{ {
t->grab_bar = val; t->grab_bar = val;
} }
else if (strcmp("grabBarButton", index) == 0) else if (strcmp("grabBarButton", index) == 0)
{ {
t->grab_bar_button = val; t->grab_bar_button = val;
} }
else if (strcmp("grab_button_text", index) == 0) else if (strcmp("grab_button_text", index) == 0)
{ {
t->grab_button_text = val; t->grab_button_text = val;
} }
else if (strcmp("grabText", index) == 0) else if (strcmp("grabText", index) == 0)
{ {
t->grab_text = val; t->grab_text = val;
} }
else if (strcmp("workArea", index) == 0) else if (strcmp("workArea", index) == 0)
{ {
t->work_area = val; t->work_area = val;
} }
else if (strcmp("workButton", index) == 0) else if (strcmp("workButton", index) == 0)
{ {
t->work_button = val; t->work_button = val;
} }
else if (strcmp("workButtonText", index) == 0) else if (strcmp("workButtonText", index) == 0)
{ {
t->work_button_text = val; t->work_button_text = val;
} }
else if (strcmp("workGraph", index) == 0) else if (strcmp("workGraph", index) == 0)
{ {
t->work_graph = val; t->work_graph = val;
} }
else if (strcmp("workText", index) == 0) else if (strcmp("workText", index) == 0)
{ {
t->work_text = val; t->work_text = val;
} }
else else
{ {
luaL_error(L, "wrong index: %s", index); luaL_error(L, "wrong index: %s", index);
} }
return 0; return 0;
} }
static int sycalls_eqSystemColors(lua_State* L) static int syscalls_eqSystemColors(lua_State* L)
{ {
lua_pushboolean( lua_pushboolean(
L, L,
memcmp( memcmp(
luaL_checkudata(L, 1, syscalls_SystemColors_metatable_name), luaL_checkudata(L, 1, syscalls_SystemColors_metatable_name),
luaL_checkudata(L, 2, syscalls_SystemColors_metatable_name), luaL_checkudata(L, 2, syscalls_SystemColors_metatable_name),
sizeof(ksys_colors_table_t) sizeof(ksys_colors_table_t)
) )
); );
return 1; return 1;
} }
static int sycalls_gcSystemColors(lua_State* L) static int syscalls_gcSystemColors(lua_State* L)
{ {
ksys_colors_table_t* t = luaL_checkudata(L, 1, syscalls_SystemColors_metatable_name); ksys_colors_table_t* t = luaL_checkudata(L, 1, syscalls_SystemColors_metatable_name);
free(t); free(t);
return 1; return 1;
} }
ksys_colors_table_t* syscalls_pushSystemColors(lua_State* L) ksys_colors_table_t* syscalls_pushSystemColors(lua_State* L)
{ {
DEBUG_LINE("push system colors table"); DEBUG_LINE("push system colors table");
ksys_colors_table_t* colorsTable = lua_newuserdata(L, sizeof(ksys_colors_table_t));
luaL_setmetatable(L, syscalls_SystemColors_metatable_name);
return colorsTable; ksys_colors_table_t* colorsTable = lua_newuserdata(L, sizeof(ksys_colors_table_t));
luaL_setmetatable(L, syscalls_SystemColors_metatable_name);
return colorsTable;
} }
static const luaL_Reg syscalls_SystemColors_m[] = { static const luaL_Reg syscalls_SystemColors_m[] = {
{"__index", syscalls_indexSystemColors}, {"__index", syscalls_indexSystemColors},
{"__newindex", syscalls_newindexSystemColors}, {"__newindex", syscalls_newindexSystemColors},
{"__eq", sycalls_eqSystemColors}, {"__eq", syscalls_eqSystemColors},
{"__gc", sycalls_gcSystemColors}, {"__gc", syscalls_gcSystemColors},
{NULL, NULL} {NULL, NULL}
}; };
static const luaL_Reg syscalls_SystemColors_lib[] = { static const luaL_Reg syscalls_SystemColors_lib[] = {
{"new", syscalls_newSystemColors}, {"new", syscalls_newSystemColors},
{NULL, NULL} {NULL, NULL}
}; };
void syscalls_register_SystemColors(lua_State* L) void syscalls_register_SystemColors(lua_State* L)
{ {
luaL_newlib(L, syscalls_SystemColors_lib); luaL_newlib(L, syscalls_SystemColors_lib);
lua_setfield(L, -2, "SystemColors"); lua_setfield(L, -2, "SystemColors");
luaL_newmetatable(L, syscalls_SystemColors_metatable_name); luaL_newmetatable(L, syscalls_SystemColors_metatable_name);
luaL_setfuncs(L, syscalls_SystemColors_m, 0); luaL_setfuncs(L, syscalls_SystemColors_m, 0);
lua_pop(L, 1); lua_pop(L, 1);
} }

View File

@@ -1,5 +1,5 @@
#ifndef _SYSCALLS_SYSTEMCOLORS_H_ #ifndef _SYSCALLS_SYSTEM_COLORS_H_
#define _SYSCALLS_SYSTEMCOLORS_H_ #define _SYSCALLS_SYSTEM_COLORS_H_
#include <lua.h> #include <lua.h>
#include <lualib.h> #include <lualib.h>
@@ -17,4 +17,4 @@ ksys_colors_table_t* syscalls_pushSystemColors(lua_State* L);
*/ */
void syscalls_register_SystemColors(lua_State* L); void syscalls_register_SystemColors(lua_State* L);
#endif // _SYSCALLS_SYSTEMCOLORS_H_ #endif // _SYSCALLS_SYSTEM_COLORS_H_

View File

@@ -5,5 +5,5 @@ local SystemColors = syscalls.GetSystemColors()
print(SystemColors) print(SystemColors)
for i, v in pairs(SystemColors) do for i, v in pairs(SystemColors) do
print(i, v) print(i, v)
end end

View File

@@ -1,4 +1,3 @@
for i, v in pairs(require("syscalls")) do for i, v in pairs(require("syscalls")) do
print(i, v) print(i, v)
end end