From 273e9edfc701c563cb83af0b3157649fe8945ec3 Mon Sep 17 00:00:00 2001 From: Egor00f Date: Sat, 5 Apr 2025 17:27:29 +0500 Subject: [PATCH] make working classes && add vscode config && add lua submodule --- .gitmodules | 3 + .vscode/c_cpp_properties.json | 23 +++ .vscode/extensions.json | 8 + .vscode/settings.json | 5 + Makefile | 20 +- lua | 1 + src/ARP_entry.c | 64 ++++--- src/ARP_entry.h | 10 +- src/debug.h | 23 +++ src/syscalls.c | 349 +++++++++++++++++----------------- src/systemColors.c | 46 +++-- src/systemColors.h | 13 +- tests/SystemColors.lua | 9 + tests/libraryStruct.lua | 4 + 14 files changed, 337 insertions(+), 241 deletions(-) create mode 100644 .gitmodules create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json create mode 160000 lua create mode 100644 src/debug.h create mode 100644 tests/SystemColors.lua create mode 100644 tests/libraryStruct.lua diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..3129a53 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lua"] + path = lua + url = https://git.kolibrios.org/lua/lua.git diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..936f463 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,23 @@ +{ + "configurations": [ + { + "name": "Release", + "includePath": [ + "${workspaceFolder}/lua/src", + "${workspaceFolder}/../kolibrios/contrib/sdk/sources/newlib/libc/include" + ], + "defines": [] + }, + { + "name": "Debug", + "includePath": [ + "${workspaceFolder}/lua/src", + "${workspaceFolder}/../kolibrios/contrib/sdk/sources/newlib/libc/include" + ], + "defines": [ + "NDEBUG" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..aa1e4ad --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,8 @@ +{ + "recommendations": [ + "sumneko.lua", + "ms-vscode.cpptools", + "streetsidesoftware.code-spell-checker-russian", + "streetsidesoftware.code-spell-checker" + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..9deab0a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "stdlib.h": "c" + } +} \ No newline at end of file diff --git a/Makefile b/Makefile index 1b6e50b..230d05c 100644 --- a/Makefile +++ b/Makefile @@ -6,22 +6,22 @@ STRIP=kos32-strip OBJCOPY=kos32-objcopy STD=-std=gnu99 CFLAGS=$(SYSCFLAGS) -O2 -Wall -Wextra -DLUA_COMPAT_5_3 $(STD) $(MYCFLAGS) -LDFLAGS=$(SYSLDFLAGS) $(MYLDFLAGS) lua$(LUA_V).dll.a -LIBS=$(SYSLIBS) $(MYLIBS) +LDFLAGS=$(SYSLDFLAGS) $(MYLDFLAGS) +LIBS=$(SYSLIBS) $(MYLIBS) $(TOOLCHAIN_PATH)/mingw32/lib/lua$(LUA_V).dll.a -ifeq ($(OS),Windows_NT) +ifeq ($(OS), Windows_NT) TOOLCHAIN_PATH=C:/MinGW/msys/1.0/home/autobuild/tools/win32 else TOOLCHAIN_PATH=/home/autobuild/tools/win32 endif -KOLIBRIOS_REPO=../../kolibrios +KOLIBRIOS_REPO=../kolibrios SDK_DIR=$(KOLIBRIOS_REPO)/contrib/sdk NewLib_DIR=$(SDK_DIR)/sources/newlib -SYSCFLAGS=-fno-ident -fomit-frame-pointer -U__WIN32__ -U_Win32 -U_WIN32 -U__MINGW32__ -UWIN32 -I$(NewLib_DIR)/libc/include -I$(TOOLCHAIN_PATH)/include +SYSCFLAGS=-fno-ident -fomit-frame-pointer -U__WIN32__ -U_Win32 -U_WIN32 -U__MINGW32__ -UWIN32 -I$(NewLib_DIR)/libc/include -I$(abspath .)/lua/src SYSLDFLAGS=--image-base 0 -Tapp-dynamic.lds SYSLIBS=-nostdlib -L $(SDK_DIR)/lib -L$(TOOLCHAIN_PATH)/lib -L$(TOOLCHAIN_PATH)/mingw32/lib -lgcc -lc.dll -ldll MYCFLAGS= @@ -29,15 +29,15 @@ MYLDFLAGS= MYLIBS= MYOBJS= -ALL_O = src/syscalls.o src/ARP_entry.o src/sytemColors.o +ALL_O = src/syscalls.o src/ARP_entry.o src/systemColors.o syscalls.dll: $(ALL_O) - $(CC) -shared -T dll.lds --entry _DllStartup -o $@ lsyscalls.o $(SYSLIBS) + $(CC) -shared -T dll.lds --entry _DllStartup -o $@ $(ALL_O) $(LIBS) clean: rm -f $(ALL_O) syscalls.dll -src/syscalls.o: src/syscalls.c -src/ARP_entry.o: src/ARP_entry.c src/ARP_entry.h -src/sytemColors.o: src/sytemColors.c src/sytemColors.h +src/syscalls.o: src/syscalls.c src/systemColors.h src/ARP_entry.h src/scancodes.h +src/ARP_entry.o: src/ARP_entry.c src/ARP_entry.h src/debug.h +src/systemColors.o: src/systemColors.c src/systemColors.h src/debug.h diff --git a/lua b/lua new file mode 160000 index 0000000..eae2ea0 --- /dev/null +++ b/lua @@ -0,0 +1 @@ +Subproject commit eae2ea0aaa2c4d0ad9e9c5c6594f9b2378971ced diff --git a/src/ARP_entry.c b/src/ARP_entry.c index dea5b14..cc13acb 100644 --- a/src/ARP_entry.c +++ b/src/ARP_entry.c @@ -1,27 +1,30 @@ #include "ARP_entry.h" +#include "debug.h" #include #include #include #include -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); } diff --git a/src/ARP_entry.h b/src/ARP_entry.h index aa783ce..31b8fd6 100644 --- a/src/ARP_entry.h +++ b/src/ARP_entry.h @@ -22,15 +22,15 @@ struct ARP_entry /* * Create ARPEntry */ -void syscalls_pushARPEntry(lua_State *L, struct ARP_entry *entry); +struct ARP_entry* syscalls_pushARPEntry(lua_State* L); /* * shell of syscalls_createARPEntry for lua */ -int syscalls_newARPEntry(lua_State *L); -int syscalls_indexARPEntry(lua_State *L); -int syscalls_newindexARPEntry(lua_State *L); +int syscalls_newARPEntry(lua_State* L); +int syscalls_indexARPEntry(lua_State* L); +int syscalls_newindexARPEntry(lua_State* L); -void syscalls_register_ARPEntry(lua_State *L); +void syscalls_register_ARPEntry(lua_State* L); #endif diff --git a/src/debug.h b/src/debug.h new file mode 100644 index 0000000..c6342f9 --- /dev/null +++ b/src/debug.h @@ -0,0 +1,23 @@ +#ifndef __DEBUG_H__ +#define __DEBUG_H__ + +#ifdef NDEBUG + +#include +/** + * Debug out, enabled + */ +#define DEBUG_PRINT(msg) _ksys_debug_puts(msg) + +#else + +/** + * Debug out, disabled + */ +#define DEBUG_PRINT(msg) + +#endif + +#define DEBUG_LINE(msg) DEBUG_PRINT(msg); DEBUG_PRINT("\n") + +#endif // __DEBUG_H__ diff --git a/src/syscalls.c b/src/syscalls.c index 17de304..c923422 100644 --- a/src/syscalls.c +++ b/src/syscalls.c @@ -13,8 +13,11 @@ #include "scancodes.h" #include "ARP_entry.h" + #include "systemColors.h" + + /* Режим ввода с клавиатуры @@ -31,7 +34,7 @@ static ksys_key_input_mode_t syscalls_KeyInputState = KSYS_KEY_INPUT_MODE_ASCII; обновляется функцией syscalls_updateScreenSize */ -static ksys_pos_t syscalls_screenSizeCache = {0}; +static ksys_pos_t syscalls_screenSizeCache = { 0 }; /* @@ -39,7 +42,7 @@ static ksys_pos_t syscalls_screenSizeCache = {0}; */ -inline void syscalls_ReturnIntegerOrNil(LUA_INTEGER value, lua_State *L) +inline void syscalls_ReturnIntegerOrNil(LUA_INTEGER value, lua_State* L) { if (value == -1) { @@ -51,7 +54,7 @@ inline void syscalls_ReturnIntegerOrNil(LUA_INTEGER value, lua_State *L) } } -inline void syscalls_ReturnIntegerValueOrNil(LUA_INTEGER cond, LUA_INTEGER value, lua_State *L) +inline void syscalls_ReturnIntegerValueOrNil(LUA_INTEGER cond, LUA_INTEGER value, lua_State* L) { if (cond == -1) { @@ -63,7 +66,7 @@ inline void syscalls_ReturnIntegerValueOrNil(LUA_INTEGER cond, LUA_INTEGER value } } -inline void syscalls_ReturnTrueOrNil(LUA_INTEGER value, lua_State *L) +inline void syscalls_ReturnTrueOrNil(LUA_INTEGER value, lua_State* L) { if (value == -1) { @@ -75,7 +78,7 @@ inline void syscalls_ReturnTrueOrNil(LUA_INTEGER value, lua_State *L) } } -inline void syscalls_ReturnStringOrNil(LUA_INTEGER cond, const char *value, lua_State *L) +inline void syscalls_ReturnStringOrNil(LUA_INTEGER cond, const char* value, lua_State* L) { if (cond == -1) { @@ -90,7 +93,7 @@ inline void syscalls_ReturnStringOrNil(LUA_INTEGER cond, const char *value, lua_ -static int syscalls_createWindow(lua_State *L) +static int syscalls_createWindow(lua_State* L) { uint32_t x = luaL_checkinteger(L, 1); uint32_t y = luaL_checkinteger(L, 2); @@ -124,7 +127,7 @@ static int syscalls_createWindow(lua_State *L) return 0; } -static int syscalls_changeWindow(lua_State *L) +static int syscalls_changeWindow(lua_State* L) { _ksys_change_window( luaL_checkinteger(L, 1), @@ -135,30 +138,30 @@ static int syscalls_changeWindow(lua_State *L) return 0; } -static int syscalls_setWindowTitle(lua_State *L) +static int syscalls_setWindowTitle(lua_State* L) { _ksys_set_window_title(luaL_checkstring(L, 1)); return 0; } -static int syscalls_startRedraw(lua_State *L) +static int syscalls_startRedraw(lua_State* L) { _ksys_start_draw(); return 0; } -static int syscalls_endRedraw(lua_State *L) +static int syscalls_endRedraw(lua_State* L) { _ksys_end_draw(); return 0; } -static int syscalls_SetSkin(lua_State *L) +static int syscalls_SetSkin(lua_State* L) { - uint ret; + unsigned ret; asm_inline( "int $0x40" : "=a"(ret) @@ -169,7 +172,7 @@ static int syscalls_SetSkin(lua_State *L) return 1; } -static int syscalls_GetSkinTilteArea(lua_State *L) +static int syscalls_GetSkinTilteArea(lua_State* L) { ksys_pos_t leftRight, topBottom; @@ -195,7 +198,7 @@ static int syscalls_GetSkinTilteArea(lua_State *L) return 1; } -static int syscalls_SetWorkArea(lua_State *L) +static int syscalls_SetWorkArea(lua_State* L) { uint32_t left = luaL_checkinteger(L, 1); uint32_t top = luaL_checkinteger(L, 2); @@ -208,7 +211,7 @@ static int syscalls_SetWorkArea(lua_State *L) return 0; } -static int syscalls_GetWorkArea(lua_State *L) +static int syscalls_GetWorkArea(lua_State* L) { ksys_pos_t leftlright; ksys_pos_t toplbottom; @@ -216,7 +219,7 @@ static int syscalls_GetWorkArea(lua_State *L) asm_inline( "int $0x40" :"=a"(leftlright), "=b"(toplbottom) - :"a"(48), "b"(5) + : "a"(48), "b"(5) ); lua_createtable(L, 0, 4); @@ -236,7 +239,7 @@ static int syscalls_GetWorkArea(lua_State *L) return 1; } -static int syscalls_defineButton(lua_State *L) +static int syscalls_defineButton(lua_State* L) { _ksys_define_button( luaL_checkinteger(L, 1), @@ -249,19 +252,19 @@ static int syscalls_defineButton(lua_State *L) return 0; } -static int syscalls_deleteButton(lua_State *L) +static int syscalls_deleteButton(lua_State* L) { _ksys_delete_button(luaL_checkinteger(L, 1)); return 0; } -static int syscalls_SetButtonsStyle(lua_State *L) +static int syscalls_SetButtonsStyle(lua_State* L) { uint32_t style = luaL_checkinteger(L, 1); asm_inline( "int $0x40" ::"a"(48), "b"(1), "c"(style)); - + asm_inline( "int $0x40" ::"a"(48), "b"(0), "c"(0)); @@ -274,7 +277,7 @@ static int syscalls_SetButtonsStyle(lua_State *L) _ksys_draw_bitmap(,); } */ -static int syscalls_drawPixel(lua_State *L) +static int syscalls_drawPixel(lua_State* L) { _ksys_draw_pixel( luaL_checkinteger(L, 1), @@ -284,7 +287,7 @@ static int syscalls_drawPixel(lua_State *L) return 0; } -static int syscalls_threadInfo(lua_State *L) +static int syscalls_threadInfo(lua_State* L) { ksys_thread_t t; @@ -334,7 +337,7 @@ static int syscalls_threadInfo(lua_State *L) return 1; } -static int syscalls_KillBySlot(lua_State *L) +static int syscalls_KillBySlot(lua_State* L) { _ksys_kill_by_slot( @@ -343,84 +346,84 @@ static int syscalls_KillBySlot(lua_State *L) return 0; } -static int syscalls_setEventMask(lua_State *L) +static int syscalls_setEventMask(lua_State* L) { _ksys_set_event_mask(luaL_checkinteger(L, 1)); return 0; } -static int syscalls_waitEvent(lua_State *L) +static int syscalls_waitEvent(lua_State* L) { lua_pushinteger(L, _ksys_wait_event()); return 1; } -static int syscalls_checkEvent(lua_State *L) +static int syscalls_checkEvent(lua_State* L) { lua_pushinteger(L, _ksys_check_event()); return 1; } -static int syscalls_waitEventTimeout(lua_State *L) +static int syscalls_waitEventTimeout(lua_State* L) { lua_pushinteger(L, _ksys_wait_event_timeout(luaL_checkinteger(L, 1))); return 1; } -static int syscalls_getFreeRam(lua_State *L) +static int syscalls_getFreeRam(lua_State* L) { lua_pushinteger(L, _ksys_get_ram_size()); return 1; } -static int syscalls_getRamSize(lua_State *L) +static int syscalls_getRamSize(lua_State* L) { lua_pushinteger(L, _ksys_get_full_ram()); return 1; } -static int syscalls_shutdownPowerOff(lua_State *L) +static int syscalls_shutdownPowerOff(lua_State* L) { _ksys_shutdown(KSYS_SHD_POWEROFF); return 0; } -static int syscalls_shutdownReboot(lua_State *L) +static int syscalls_shutdownReboot(lua_State* L) { _ksys_shutdown(KSYS_SHD_REBOOT); return 0; } -static int syscalls_shutdownRestartKRN(lua_State *L) +static int syscalls_shutdownRestartKRN(lua_State* L) { _ksys_shutdown(KSYS_SHD_RESTART_KRN); return 0; } -static int syscalls_focusWindow(lua_State *L) +static int syscalls_focusWindow(lua_State* L) { _ksys_focus_window(luaL_checkinteger(L, 1)); return 0; } -static int syscalls_unfocusWindow(lua_State *L) +static int syscalls_unfocusWindow(lua_State* L) { _ksys_unfocus_window(luaL_checkinteger(L, 1)); return 0; } -static int syscalls_getButton(lua_State *L) +static int syscalls_getButton(lua_State* L) { uint32_t val; @@ -449,7 +452,7 @@ static void syscalls_updateScreenSize() syscalls_screenSizeCache = _ksys_screen_size(); } -static int syscalls_screenSize(lua_State *L) +static int syscalls_screenSize(lua_State* L) { syscalls_updateScreenSize(); @@ -464,11 +467,11 @@ static int syscalls_screenSize(lua_State *L) return 1; } -/* +/* Backgound */ -static int syscalls_backgroundSetSize(lua_State *L) +static int syscalls_backgroundSetSize(lua_State* L) { _ksys_bg_set_size( luaL_checkinteger(L, 1), @@ -477,7 +480,7 @@ static int syscalls_backgroundSetSize(lua_State *L) return 0; } -static int syscalls_backgroundPutPixel(lua_State *L) +static int syscalls_backgroundPutPixel(lua_State* L) { _ksys_bg_put_pixel( luaL_checkinteger(L, 1), @@ -488,21 +491,21 @@ static int syscalls_backgroundPutPixel(lua_State *L) return 0; } -static int syscalls_backgroundRedraw(lua_State *L) +static int syscalls_backgroundRedraw(lua_State* L) { _ksys_bg_redraw(); return 0; } -static int syscalls_getCPUClock(lua_State *L) +static int syscalls_getCPUClock(lua_State* L) { lua_pushinteger(L, _ksys_get_cpu_clock()); return 1; } -static int syscalls_drawLine(lua_State *L) +static int syscalls_drawLine(lua_State* L) { _ksys_draw_line( luaL_checkinteger(L, 1), @@ -534,14 +537,14 @@ enum TextScale TextScale_SIZE_64x128 // 8x 8x16 }; -static void syscall_drawText(const char *text, uint32_t x, uint32_t y, ksys_color_t color, enum TextScale size, uint32_t len, bool fillBackground, ksys_color_t backgroundColor) +static void syscall_drawText(const char* text, uint32_t x, uint32_t y, ksys_color_t color, enum TextScale size, uint32_t len, bool fillBackground, ksys_color_t backgroundColor) { enum DrawTextEncoding { cp866_6x9 = 0, cp866_8x16 = 1, utf8 = 3, - utf16= 4 + utf16 = 4 }; enum scale @@ -560,7 +563,7 @@ static void syscall_drawText(const char *text, uint32_t x, uint32_t y, ksys_colo color |= (fillBackground << 30); - switch(size) + switch (size) { case TextScale_SIZE_6x9: color |= (cp866_8x16 << 28) | (scale_x1 << 24); @@ -623,7 +626,7 @@ static void syscall_drawText(const char *text, uint32_t x, uint32_t y, ksys_colo "D"(backgroundColor)); } -static int syscalls_drawText(lua_State *L) +static int syscalls_drawText(lua_State* L) { syscall_drawText( luaL_checkstring(L, 1), @@ -638,7 +641,7 @@ static int syscalls_drawText(lua_State *L) return 0; } -static int syscalls_drawRectangle(lua_State *L) +static int syscalls_drawRectangle(lua_State* L) { _ksys_draw_bar( luaL_checkinteger(L, 1), @@ -650,7 +653,7 @@ static int syscalls_drawRectangle(lua_State *L) return 0; } -static int syscalls_ReadPoint(lua_State *L) +static int syscalls_ReadPoint(lua_State* L) { ksys_color_t color; @@ -670,20 +673,18 @@ static int syscalls_ReadPoint(lua_State *L) return 1; } -static int syscalls_getSystemColors(lua_State *L) +static int syscalls_getSystemColors(lua_State* L) { - ksys_colors_table_t *t = malloc(sizeof(ksys_colors_table_t)); + ksys_colors_table_t* t = syscalls_pushSystemColors(L); _ksys_get_system_colors(t); - syscalls_pushSystemColors(L, t); - return 1; } -static int syscalls_SetSystemColors(lua_State *L) +static int syscalls_SetSystemColors(lua_State* L) { - ksys_colors_table_t *t = (ksys_colors_table_t *)lua_touserdata(L, 1); + ksys_colors_table_t* t = (ksys_colors_table_t*)lua_touserdata(L, 1); asm_inline( "int $0x40" ::"a"(48), "b"(2), "c"(t), "d"(40)); @@ -694,14 +695,14 @@ static int syscalls_SetSystemColors(lua_State *L) return 0; } -static int syscalls_getSkinHeight(lua_State *L) +static int syscalls_getSkinHeight(lua_State* L) { lua_pushinteger(L, _ksys_get_skin_height()); return 1; } -static int syscalls_setKeyInputMode(lua_State *L) +static int syscalls_setKeyInputMode(lua_State* L) { syscalls_KeyInputState = luaL_checkinteger(L, 1); _ksys_set_key_input_mode(syscalls_KeyInputState); @@ -709,14 +710,14 @@ static int syscalls_setKeyInputMode(lua_State *L) return 0; } -static int syscalls_getKeyInputMode(lua_State *L) +static int syscalls_getKeyInputMode(lua_State* L) { lua_pushinteger(L, syscalls_KeyInputState); return 1; } -static int syscalls_getKey(lua_State *L) +static int syscalls_getKey(lua_State* L) { ksys_oskey_t a = _ksys_get_key(); @@ -751,7 +752,7 @@ static int syscalls_getKey(lua_State *L) return 2; } -static int syscalls_getControlKeyState(lua_State *L) +static int syscalls_getControlKeyState(lua_State* L) { uint32_t state = _ksys_get_control_key_state(); @@ -787,16 +788,16 @@ static int syscalls_getControlKeyState(lua_State *L) return 1; } -static int syscalls_SetHotkey(lua_State *L) +static int syscalls_SetHotkey(lua_State* L) { lua_settop(L, 1); luaL_checktype(L, 1, LUA_TTABLE); if (_ksys_set_sys_hotkey( - lua_getfield(L, -2, "Scancode"), - (lua_getfield(L, -2, "Shift")) | - (lua_getfield(L, -2, "Ctrl") << 4) | - (lua_getfield(L, -2, "Alt") << 8))) + lua_getfield(L, -2, "Scancode"), + (lua_getfield(L, -2, "Shift")) | + (lua_getfield(L, -2, "Ctrl") << 4) | + (lua_getfield(L, -2, "Alt") << 8))) { luaL_pushfail(L); } @@ -804,16 +805,16 @@ static int syscalls_SetHotkey(lua_State *L) return 1; } -static int syscalls_DeleteHotkey(lua_State *L) +static int syscalls_DeleteHotkey(lua_State* L) { lua_settop(L, 1); luaL_checktype(L, 1, LUA_TTABLE); if (_ksys_del_sys_hotkey( - lua_getfield(L, -2, "Scancode"), - lua_getfield(L, -2, "Shift") | - (lua_getfield(L, -2, "Ctrl") << 4) | - (lua_getfield(L, -2, "Alt") << 8))) + lua_getfield(L, -2, "Scancode"), + lua_getfield(L, -2, "Shift") | + (lua_getfield(L, -2, "Ctrl") << 4) | + (lua_getfield(L, -2, "Alt") << 8))) { luaL_pushfail(L); } @@ -821,7 +822,7 @@ static int syscalls_DeleteHotkey(lua_State *L) return 1; } -static int syscalls_LockNormalInput(lua_State *L) +static int syscalls_LockNormalInput(lua_State* L) { asm_inline( "int $0x40" ::"a"(66), "b"(6)); @@ -829,7 +830,7 @@ static int syscalls_LockNormalInput(lua_State *L) return 0; } -static int syscalls_UnlockNormalInput(lua_State *L) +static int syscalls_UnlockNormalInput(lua_State* L) { asm_inline( "int $0x40" ::"a"(66), "b"(7)); @@ -841,7 +842,7 @@ static int syscalls_UnlockNormalInput(lua_State *L) Mouse Funcs */ -static int syscalls_getMousePositionScreen(lua_State *L) +static int syscalls_getMousePositionScreen(lua_State* L) { ksys_pos_t pos = _ksys_get_mouse_pos(KSYS_MOUSE_SCREEN_POS); @@ -856,7 +857,7 @@ static int syscalls_getMousePositionScreen(lua_State *L) return 1; } -static int syscalls_getMousePositionWindow(lua_State *L) +static int syscalls_getMousePositionWindow(lua_State* L) { ksys_pos_t pos = _ksys_get_mouse_pos(KSYS_MOUSE_WINDOW_POS); @@ -871,7 +872,7 @@ static int syscalls_getMousePositionWindow(lua_State *L) return 1; } -static int syscalls_getMouseWheels(lua_State *L) +static int syscalls_getMouseWheels(lua_State* L) { uint32_t state = _ksys_get_mouse_wheels(); @@ -886,7 +887,7 @@ static int syscalls_getMouseWheels(lua_State *L) return 1; } -void createMouseState(uint32_t state, lua_State *L) +void createMouseState(uint32_t state, lua_State* L) { lua_pushboolean(L, state & KSYS_MOUSE_LBUTTON_PRESSED); lua_setfield(L, -2, "LeftButton"); @@ -904,7 +905,7 @@ void createMouseState(uint32_t state, lua_State *L) lua_setfield(L, -2, "Button5"); } -static int syscalls_getMouseButtons(lua_State *L) +static int syscalls_getMouseButtons(lua_State* L) { lua_createtable(L, 0, 5); @@ -913,7 +914,7 @@ static int syscalls_getMouseButtons(lua_State *L) return 1; } -static int syscalls_getMouseEvents(lua_State *L) +static int syscalls_getMouseEvents(lua_State* L) { uint32_t state = _ksys_get_mouse_eventstate(); @@ -964,28 +965,28 @@ inline uint32_t getMouseSettings(ksys_mouse_settings_t settings) return result; } -static int syscalls_GetMouseSpeed(lua_State *L) +static int syscalls_GetMouseSpeed(lua_State* L) { lua_pushinteger(L, getMouseSettings(KSYS_MOUSE_GET_SPEED)); return 1; } -static int syscalls_GetMouseSens(lua_State *L) +static int syscalls_GetMouseSens(lua_State* L) { lua_pushinteger(L, getMouseSettings(KSYS_MOUSE_GET_SENS)); return 1; } -static int syscalls_GetMouseDoubleClickDelay(lua_State *L) +static int syscalls_GetMouseDoubleClickDelay(lua_State* L) { lua_pushinteger(L, getMouseSettings(KSYS_MOUSE_GET_DOUBLE_CLICK_DELAY)); return 1; } -static int syscalls_GetMouseSettings(lua_State *L) +static int syscalls_GetMouseSettings(lua_State* L) { lua_createtable(L, 0, 3); @@ -1001,7 +1002,7 @@ static int syscalls_GetMouseSettings(lua_State *L) return 1; } -static int syscalls_MouseSimulateState(lua_State *L) +static int syscalls_MouseSimulateState(lua_State* L) { lua_settop(L, 1); luaL_checktype(L, 1, LUA_TTABLE); @@ -1015,45 +1016,45 @@ static int syscalls_MouseSimulateState(lua_State *L) _ksys_set_mouse_settings( KSYS_MOUSE_SIM_STATE, (luaL_checkinteger(L, -1) << 4) | - (luaL_checkinteger(L, -2) << 3) | - (luaL_checkinteger(L, -3) << 2) | - (luaL_checkinteger(L, -4) << 1) | - (luaL_checkinteger(L, -5))); + (luaL_checkinteger(L, -2) << 3) | + (luaL_checkinteger(L, -3) << 2) | + (luaL_checkinteger(L, -4) << 1) | + (luaL_checkinteger(L, -5))); lua_pop(L, 2); return 1; } -static int syscalls_SetMouseSpeed(lua_State *L) +static int syscalls_SetMouseSpeed(lua_State* L) { _ksys_set_mouse_settings(KSYS_MOUSE_SET_SPEED, luaL_checkinteger(L, 1)); return 0; } -static int syscalls_SetMouseSens(lua_State *L) +static int syscalls_SetMouseSens(lua_State* L) { _ksys_set_mouse_settings(KSYS_MOUSE_SET_SENS, luaL_checkinteger(L, 1)); return 0; } -static int syscalls_SetMousePos(lua_State *L) +static int syscalls_SetMousePos(lua_State* L) { _ksys_set_mouse_pos(luaL_checkinteger(L, 1), luaL_checkinteger(L, 2)); return 0; } -static int syscalls_SetMouseDoubleClickDelay(lua_State *L) +static int syscalls_SetMouseDoubleClickDelay(lua_State* L) { _ksys_set_mouse_settings(KSYS_MOUSE_SET_DOUBLE_CLICK_DELAY, luaL_checkinteger(L, 1)); return 0; } -static int syscalls_SetMouseSettings(lua_State *L) +static int syscalls_SetMouseSettings(lua_State* L) { lua_settop(L, 1); luaL_checktype(L, 1, LUA_TTABLE); @@ -1069,19 +1070,19 @@ static int syscalls_SetMouseSettings(lua_State *L) return 0; } -static int syscalls_LoadCursor(lua_State *L) +static int syscalls_LoadCursor(lua_State* L) { lua_pushlightuserdata( L, _ksys_load_cursor( - (void *)luaL_checkstring(L, 1), + (void*)luaL_checkstring(L, 1), KSYS_CURSOR_FROM_FILE | - (luaL_checkinteger(L, 2) << 24) | - (luaL_checkinteger(L, 3) << 16))); + (luaL_checkinteger(L, 2) << 24) | + (luaL_checkinteger(L, 3) << 16))); return 1; } -static int syscalls_SetCursor(lua_State *L) +static int syscalls_SetCursor(lua_State* L) { lua_islightuserdata(L, 1); lua_pushlightuserdata( @@ -1091,25 +1092,25 @@ static int syscalls_SetCursor(lua_State *L) return 1; } -static int syscalls_DeleteCursor(lua_State *L) +static int syscalls_DeleteCursor(lua_State* L) { _ksys_delete_cursor(lua_touserdata(L, 1)); return 0; } -/* - network funcs +/* + network funcs */ -static int syscalls_GetDevicesNum(lua_State *L) +static int syscalls_GetDevicesNum(lua_State* L) { uint32_t num; asm_inline( "int $0x40" :"=a"(num) - :"a"(74), "b"(-1) + : "a"(74), "b"(-1) ); lua_pushinteger(L, num); @@ -1117,7 +1118,7 @@ static int syscalls_GetDevicesNum(lua_State *L) return 1; } -static int syscalls_GetDeviceType(lua_State *L) +static int syscalls_GetDeviceType(lua_State* L) { uint32_t type; @@ -1133,7 +1134,7 @@ static int syscalls_GetDeviceType(lua_State *L) return 1; } -static int syscalls_GetDeviceName(lua_State *L) +static int syscalls_GetDeviceName(lua_State* L) { char name[64]; uint32_t ret; @@ -1149,7 +1150,7 @@ static int syscalls_GetDeviceName(lua_State *L) return 1; } -static int syscalls_ResetDevice(lua_State *L) +static int syscalls_ResetDevice(lua_State* L) { uint32_t ret = 0; @@ -1163,7 +1164,7 @@ static int syscalls_ResetDevice(lua_State *L) return 1; } -static int syscalls_StopDevice(lua_State *L) +static int syscalls_StopDevice(lua_State* L) { uint32_t ret = 0; uint8_t device = luaL_checkinteger(L, 1); @@ -1178,7 +1179,7 @@ static int syscalls_StopDevice(lua_State *L) return 1; } -static int syscalls_GetTXPacketCount(lua_State *L) +static int syscalls_GetTXPacketCount(lua_State* L) { uint32_t num; uint8_t device = luaL_checkinteger(L, 1); @@ -1193,7 +1194,7 @@ static int syscalls_GetTXPacketCount(lua_State *L) return 1; } -static int syscalls_GetRXPacketCount(lua_State *L) +static int syscalls_GetRXPacketCount(lua_State* L) { uint32_t num; uint8_t device = luaL_checkinteger(L, 1); @@ -1208,7 +1209,7 @@ static int syscalls_GetRXPacketCount(lua_State *L) return 1; } -static int syscalls_GetTXByteCount(lua_State *L) +static int syscalls_GetTXByteCount(lua_State* L) { int num; uint32_t NUM; @@ -1227,7 +1228,7 @@ static int syscalls_GetTXByteCount(lua_State *L) return 1; } -static int syscalls_GetRXByteCount(lua_State *L) +static int syscalls_GetRXByteCount(lua_State* L) { int num; uint32_t NUM; @@ -1246,7 +1247,7 @@ static int syscalls_GetRXByteCount(lua_State *L) return 1; } -static int syscalls_GetTXErrorPacketCount(lua_State *L) +static int syscalls_GetTXErrorPacketCount(lua_State* L) { int num; uint32_t NUM; @@ -1265,7 +1266,7 @@ static int syscalls_GetTXErrorPacketCount(lua_State *L) return 1; } -static int syscalls_GetTXDropPacketCount(lua_State *L) +static int syscalls_GetTXDropPacketCount(lua_State* L) { int num; uint32_t NUM; @@ -1284,7 +1285,7 @@ static int syscalls_GetTXDropPacketCount(lua_State *L) return 1; } -static int syscalls_GetTXMissPacketCount(lua_State *L) +static int syscalls_GetTXMissPacketCount(lua_State* L) { int num; uint32_t NUM; @@ -1303,7 +1304,7 @@ static int syscalls_GetTXMissPacketCount(lua_State *L) return 1; } -static int syscalls_GetRXErrorPacketCount(lua_State *L) +static int syscalls_GetRXErrorPacketCount(lua_State* L) { int num; uint32_t NUM; @@ -1322,7 +1323,7 @@ static int syscalls_GetRXErrorPacketCount(lua_State *L) return 1; } -static int syscalls_GetRXDropPacketCount(lua_State *L) +static int syscalls_GetRXDropPacketCount(lua_State* L) { int num; uint32_t NUM; @@ -1332,13 +1333,13 @@ static int syscalls_GetRXDropPacketCount(lua_State *L) "int $0x40" : "=a"(num), "=b"(NUM) : "a"(74), "b"(15 | device << 8)); - + syscalls_ReturnIntegerValueOrNil(num, (uint64_t)(num | NUM << 31), L); return 1; } -static int syscalls_GetRXMissPacketCount(lua_State *L) +static int syscalls_GetRXMissPacketCount(lua_State* L) { int num; uint32_t NUM; @@ -1364,7 +1365,7 @@ enum ConnectionStatus FullDuplex = 0b10 // }; -static int syscalls_GetConnectionStatus(lua_State *L) +static int syscalls_GetConnectionStatus(lua_State* L) { int num; uint8_t device = luaL_checkinteger(L, 1); @@ -1378,12 +1379,12 @@ static int syscalls_GetConnectionStatus(lua_State *L) lua_pushnil(L); else lua_pushinteger(L, num & 0x101); - lua_pushinteger(L, (num & FullDuplex) != 0); + lua_pushinteger(L, (num & FullDuplex) != 0); return 2; } -static int syscalls_ReadMAC(lua_State *L) +static int syscalls_ReadMAC(lua_State* L) { uint32_t eax, ebx; uint8_t device = luaL_checkinteger(L, 1); @@ -1407,7 +1408,7 @@ typedef enum SYSCALLS_PROTOCOLS ARP = 5 } SYSCALLS_PROTOCOLS; -inline int syscalls_ReadPacketSend(lua_State *L, SYSCALLS_PROTOCOLS protocol) +inline int syscalls_ReadPacketSend(lua_State* L, SYSCALLS_PROTOCOLS protocol) { uint32_t eax; uint8_t device = luaL_checkinteger(L, 1); @@ -1422,7 +1423,7 @@ inline int syscalls_ReadPacketSend(lua_State *L, SYSCALLS_PROTOCOLS protocol) return 1; } -inline int syscalls_ReadPacketReceive(lua_State *L, SYSCALLS_PROTOCOLS protocol) +inline int syscalls_ReadPacketReceive(lua_State* L, SYSCALLS_PROTOCOLS protocol) { uint32_t eax; uint8_t device = luaL_checkinteger(L, 1); @@ -1439,17 +1440,17 @@ inline int syscalls_ReadPacketReceive(lua_State *L, SYSCALLS_PROTOCOLS protocol) // IPv4 -static int syscalls_IPv4ReadPacketSend(lua_State *L) +static int syscalls_IPv4ReadPacketSend(lua_State* L) { return syscalls_ReadPacketSend(L, IPv4); } -static int syscalls_IPv4ReadPacketReceive(lua_State *L) +static int syscalls_IPv4ReadPacketReceive(lua_State* L) { return syscalls_ReadPacketReceive(L, IPv4); } -static int syscalls_ReadIPv4Address(lua_State *L) +static int syscalls_ReadIPv4Address(lua_State* L) { uint32_t eax; uint8_t device = luaL_checkinteger(L, 1); @@ -1464,7 +1465,7 @@ static int syscalls_ReadIPv4Address(lua_State *L) return 1; } -static int syscalls_SetIPv4Address(lua_State *L) +static int syscalls_SetIPv4Address(lua_State* L) { uint32_t eax; uint8_t device = luaL_checkinteger(L, 1); @@ -1480,7 +1481,7 @@ static int syscalls_SetIPv4Address(lua_State *L) return 1; } -static int syscalls_ReadIPv4DNSAddress(lua_State *L) +static int syscalls_ReadIPv4DNSAddress(lua_State* L) { uint32_t eax; uint8_t device = luaL_checkinteger(L, 1); @@ -1495,7 +1496,7 @@ static int syscalls_ReadIPv4DNSAddress(lua_State *L) return 1; } -static int syscalls_SetIPv4DNSAddress(lua_State *L) +static int syscalls_SetIPv4DNSAddress(lua_State* L) { uint32_t eax; uint8_t device = luaL_checkinteger(L, 1); @@ -1511,7 +1512,7 @@ static int syscalls_SetIPv4DNSAddress(lua_State *L) return 1; } -static int syscalls_ReadIPv4SubnetMask(lua_State *L) +static int syscalls_ReadIPv4SubnetMask(lua_State* L) { uint32_t eax; uint8_t device = luaL_checkinteger(L, 1); @@ -1526,7 +1527,7 @@ static int syscalls_ReadIPv4SubnetMask(lua_State *L) return 1; } -static int syscalls_SetIPv4SubnetMask(lua_State *L) +static int syscalls_SetIPv4SubnetMask(lua_State* L) { uint32_t eax; uint8_t device = luaL_checkinteger(L, 1); @@ -1542,7 +1543,7 @@ static int syscalls_SetIPv4SubnetMask(lua_State *L) return 1; } -static int syscalls_ReadIPv4Gateway(lua_State *L) +static int syscalls_ReadIPv4Gateway(lua_State* L) { uint32_t eax; uint8_t device = luaL_checkinteger(L, 1); @@ -1557,7 +1558,7 @@ static int syscalls_ReadIPv4Gateway(lua_State *L) return 1; } -static int syscalls_SetIPv4Gateway(lua_State *L) +static int syscalls_SetIPv4Gateway(lua_State* L) { uint32_t eax; uint8_t device = luaL_checkinteger(L, 1); @@ -1575,53 +1576,53 @@ static int syscalls_SetIPv4Gateway(lua_State *L) // ICMP -static int syscalls_ICMPReadPacketSend(lua_State *L) +static int syscalls_ICMPReadPacketSend(lua_State* L) { return syscalls_ReadPacketSend(L, ICMP); } -static int syscalls_ICMPReadPacketReceive(lua_State *L) +static int syscalls_ICMPReadPacketReceive(lua_State* L) { return syscalls_ReadPacketReceive(L, ICMP); } // UDP -static int syscalls_UDPReadPacketSend(lua_State *L) +static int syscalls_UDPReadPacketSend(lua_State* L) { return syscalls_ReadPacketSend(L, UDP); } -static int syscalls_UDPReadPacketReceive(lua_State *L) +static int syscalls_UDPReadPacketReceive(lua_State* L) { return syscalls_ReadPacketReceive(L, UDP); } // TCP -static int syscalls_TCPReadPacketSend(lua_State *L) +static int syscalls_TCPReadPacketSend(lua_State* L) { return syscalls_ReadPacketSend(L, TCP); } -static int syscalls_TCPReadPacketReceive(lua_State *L) +static int syscalls_TCPReadPacketReceive(lua_State* L) { return syscalls_ReadPacketReceive(L, TCP); } // ARP -static int syscalls_ARPReadPacketSend(lua_State *L) +static int syscalls_ARPReadPacketSend(lua_State* L) { return syscalls_ReadPacketSend(L, ARP); } -static int syscalls_ARPReadPacketReceive(lua_State *L) +static int syscalls_ARPReadPacketReceive(lua_State* L) { return syscalls_ReadPacketReceive(L, ARP); } -static int syscalls_ReadARPEntries(lua_State *L) +static int syscalls_ReadARPEntries(lua_State* L) { uint32_t eax; uint8_t device = luaL_checkinteger(L, 1); @@ -1636,29 +1637,27 @@ static int syscalls_ReadARPEntries(lua_State *L) return 1; } -static int syscalls_ReadARPEntry(lua_State *L) +static int syscalls_ReadARPEntry(lua_State* L) { uint32_t eax; uint8_t device = luaL_checkinteger(L, 1); uint32_t entryNum = luaL_checkinteger(L, 2); - struct ARP_entry buffer; + struct ARP_entry* buffer = syscalls_pushARPEntry(L); asm_inline( "int $0x40" : "=a"(eax) - : "a"(76), "b"((ARP << 24) | (device << 8) | 3), "c"(entryNum), "D"(&buffer)); - - syscalls_pushARPEntry(L, &buffer); + : "a"(76), "b"((ARP << 24) | (device << 8) | 3), "c"(entryNum), "D"(buffer)); return 1; } -static int syscalls_AddARPEntry(lua_State *L) +static int syscalls_AddARPEntry(lua_State* L) { uint32_t eax; uint8_t device = luaL_checkinteger(L, 1); uint32_t entryNum = luaL_checkinteger(L, 2); - struct ARP_entry *buffer = (struct ARP_entry *)lua_touserdata(L, 3); + struct ARP_entry* buffer = (struct ARP_entry*)lua_touserdata(L, 3); asm_inline( "int $0x40" @@ -1670,7 +1669,7 @@ static int syscalls_AddARPEntry(lua_State *L) return 1; } -static int syscalls_RemoveARPEntry(lua_State *L) +static int syscalls_RemoveARPEntry(lua_State* L) { uint32_t eax; uint8_t device = luaL_checkinteger(L, 1); @@ -1686,7 +1685,7 @@ static int syscalls_RemoveARPEntry(lua_State *L) return 1; } -static int syscalls_SendARPAnnounce(lua_State *L) +static int syscalls_SendARPAnnounce(lua_State* L) { uint32_t eax; uint8_t device = luaL_checkinteger(L, 1); @@ -1701,7 +1700,7 @@ static int syscalls_SendARPAnnounce(lua_State *L) return 1; } -static int syscalls_ReadARPConflicts(lua_State *L) +static int syscalls_ReadARPConflicts(lua_State* L) { uint32_t eax; uint8_t device = luaL_checkinteger(L, 1); @@ -1718,7 +1717,7 @@ static int syscalls_ReadARPConflicts(lua_State *L) /* Сокеты */ -static int syscalls_OpenSocket(lua_State *L) +static int syscalls_OpenSocket(lua_State* L) { int32_t socketNum; uint32_t errorCode; @@ -1730,10 +1729,10 @@ static int syscalls_OpenSocket(lua_State *L) asm_inline( "int $0x40" :"=a"(socketNum), "=b"(errorCode) - :"a"(77), "b"(0), "c"(family), "d"(type), "S"(protocol) + : "a"(77), "b"(0), "c"(family), "d"(type), "S"(protocol) ); - if(socketNum == -1) + if (socketNum == -1) { lua_pushnil(L); // Push socketNum lua_pushnumber(L, socketNum); // Push error Code @@ -1747,7 +1746,7 @@ static int syscalls_OpenSocket(lua_State *L) return 2; } -static int syscalls_CloseSocket(lua_State *L) +static int syscalls_CloseSocket(lua_State* L) { uint32_t eax; uint32_t errorCode; @@ -1763,7 +1762,7 @@ static int syscalls_CloseSocket(lua_State *L) return 1; } -static int syscalls_Bind(lua_State *L) +static int syscalls_Bind(lua_State* L) { uint32_t eax; uint32_t errorCode; @@ -1782,7 +1781,7 @@ static int syscalls_Bind(lua_State *L) return 1; } -static int syscalls_Listen(lua_State *L) +static int syscalls_Listen(lua_State* L) { uint32_t eax; uint32_t errorCode; @@ -1800,7 +1799,7 @@ static int syscalls_Listen(lua_State *L) return 1; } -static int syscalls_Connect(lua_State *L) +static int syscalls_Connect(lua_State* L) { uint32_t eax; uint32_t errorCode; @@ -1819,7 +1818,7 @@ static int syscalls_Connect(lua_State *L) return 1; } -static int syscalls_Accept(lua_State *L) +static int syscalls_Accept(lua_State* L) { uint32_t eax; uint32_t errorCode; @@ -1838,7 +1837,7 @@ static int syscalls_Accept(lua_State *L) return 1; } -static int syscalls_Send(lua_State *L) +static int syscalls_Send(lua_State* L) { uint32_t eax; uint32_t errorCode; @@ -1858,7 +1857,7 @@ static int syscalls_Send(lua_State *L) return 1; } -static int syscalls_Receive(lua_State *L) +static int syscalls_Receive(lua_State* L) { uint32_t eax; uint32_t errorCode; @@ -1878,7 +1877,7 @@ static int syscalls_Receive(lua_State *L) return 1; } -static int syscalls_GetSocketOptions(lua_State *L) +static int syscalls_GetSocketOptions(lua_State* L) { uint32_t eax; uint32_t errorCode; @@ -1896,7 +1895,7 @@ static int syscalls_GetSocketOptions(lua_State *L) return 1; } -static int syscalls_GetPairSocket(lua_State *L) +static int syscalls_GetPairSocket(lua_State* L) { int32_t firstSocketNum; uint32_t secondSocketNum; @@ -1906,7 +1905,7 @@ static int syscalls_GetPairSocket(lua_State *L) : "=a"(firstSocketNum), "=b"(secondSocketNum) : "a"(77), "b"(9)); - if(firstSocketNum == -1) + if (firstSocketNum == -1) { lua_pushnil(L); lua_pushinteger(L, secondSocketNum); @@ -2053,9 +2052,9 @@ static const luaL_Reg syscallsLib[] = { {"Receive", syscalls_Receive}, {"GetSocketOptions", syscalls_GetSocketOptions}, {"GetPairSocket", syscalls_GetPairSocket}, - {NULL, NULL}}; + {NULL, NULL} }; -static inline void syscalls_push_events(lua_State *L) +static inline void syscalls_push_events(lua_State* L) { lua_newtable(L); @@ -2088,11 +2087,11 @@ static inline void syscalls_push_events(lua_State *L) lua_pushinteger(L, KSYS_EVENT_IRQBEGIN); lua_setfield(L, -2, "IRQBegin"); - + lua_setfield(L, -2, "Event"); } -static inline void syscalls_push_buttonCodes(lua_State *L) +static inline void syscalls_push_buttonCodes(lua_State* L) { lua_newtable(L); @@ -2114,7 +2113,7 @@ static inline void syscalls_push_buttonCodes(lua_State *L) lua_setfield(L, -2, "mouseButtons"); } -static inline void syscalls_push_slotStates(lua_State *L) +static inline void syscalls_push_slotStates(lua_State* L) { lua_newtable(L); @@ -2142,7 +2141,7 @@ static inline void syscalls_push_slotStates(lua_State *L) lua_setfield(L, -2, "slotState"); } -static inline void syscalls_push_hotkey_states(lua_State *L) +static inline void syscalls_push_hotkey_states(lua_State* L) { lua_newtable(L); @@ -2165,7 +2164,7 @@ static inline void syscalls_push_hotkey_states(lua_State *L) lua_setfield(L, -2, "hotkeyStates"); } -static inline void syscalls_push_buttonsStyle(lua_State *L) +static inline void syscalls_push_buttonsStyle(lua_State* L) { lua_newtable(L); @@ -2179,7 +2178,7 @@ static inline void syscalls_push_buttonsStyle(lua_State *L) lua_setfield(L, -2, "buttonStyle"); } -static inline void syscalls_push_windowStyles(lua_State *L) +static inline void syscalls_push_windowStyles(lua_State* L) { lua_newtable(L); @@ -2201,7 +2200,7 @@ static inline void syscalls_push_windowStyles(lua_State *L) lua_setfield(L, -2, "windowStyle"); } -static inline void syscalls_push_buttons(lua_State *L) +static inline void syscalls_push_buttons(lua_State* L) { lua_newtable(L); @@ -2214,7 +2213,7 @@ static inline void syscalls_push_buttons(lua_State *L) lua_setfield(L, -2, "buttons"); } -static inline void syscalls_push_connectionStatus(lua_State *L) +static inline void syscalls_push_connectionStatus(lua_State* L) { lua_newtable(L); @@ -2236,7 +2235,7 @@ static inline void syscalls_push_connectionStatus(lua_State *L) lua_setfield(L, -2, "connectionStatus"); } -inline void syscalls_push_textSizes(lua_State *L) +inline void syscalls_push_textSizes(lua_State* L) { lua_newtable(L); @@ -2291,7 +2290,7 @@ inline void syscalls_push_textSizes(lua_State *L) lua_setfield(L, -2, "textSize"); } -LUALIB_API int luaopen_syscalls(lua_State *L) +LUALIB_API int luaopen_syscalls(lua_State* L) { luaL_newlib(L, syscallsLib); diff --git a/src/systemColors.c b/src/systemColors.c index de7041f..f7332fc 100644 --- a/src/systemColors.c +++ b/src/systemColors.c @@ -1,10 +1,14 @@ #include "systemColors.h" +#include "debug.h" #include #include + +static int syscalls_SystemColors_m_index; + int syscalls_newSystemColors(lua_State* L) { - ksys_colors_table_t* colorsTable = malloc(sizeof(ksys_colors_table_t)); + ksys_colors_table_t* colorsTable = syscalls_pushSystemColors(L); colorsTable->frame_area = luaL_optinteger(L, 1, 0); colorsTable->grab_bar = luaL_optinteger(L, 2, 0); @@ -17,13 +21,13 @@ int syscalls_newSystemColors(lua_State* L) colorsTable->work_graph = luaL_optinteger(L, 9, 0); colorsTable->work_text = luaL_optinteger(L, 10, 0); - syscalls_pushSystemColors(L, colorsTable); - return 1; } static int syscalls_indexSystemColors(lua_State* L) { + 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 char* index = luaL_checkstring(L, 2); @@ -150,35 +154,41 @@ static int sycalls_gcSystemColors(lua_State* L) { ksys_colors_table_t* t = luaL_checkudata(L, 1, syscalls_SystemColors_metatable_name); free(t); + return 1; } +ksys_colors_table_t* syscalls_pushSystemColors(lua_State* L) +{ + 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; +} + + static const luaL_Reg syscalls_SystemColors_m[] = { {"__index", syscalls_indexSystemColors}, {"__newindex", syscalls_newindexSystemColors}, {"__eq", sycalls_eqSystemColors}, - {NULL, NULL} }; - -void syscalls_pushSystemColors(lua_State* L, ksys_colors_table_t* colorsTable) -{ - *(ksys_colors_table_t**)lua_newuserdata(L, sizeof(ksys_colors_table_t)) = colorsTable; - - luaL_newlibtable(L, syscalls_SystemColors_m); - luaL_setfuncs(L, syscalls_SystemColors_m, 0); - - lua_setmetatable(L, -2); -} - + {"__gc", sycalls_gcSystemColors}, + {NULL, NULL} +}; static const luaL_Reg syscalls_SystemColors_lib[] = { {"new", syscalls_newSystemColors}, - {NULL, NULL} }; + {NULL, NULL} +}; void syscalls_register_SystemColors(lua_State* L) { luaL_newlib(L, syscalls_SystemColors_lib); - lua_setfield(L, -2, syscalls_SystemColors_name); + lua_setfield(L, -2, "SystemColors"); - luaL_newlibtable(L, syscalls_SystemColors_m); + luaL_newmetatable(L, syscalls_SystemColors_metatable_name); luaL_setfuncs(L, syscalls_SystemColors_m, 0); + + lua_pop(L, 1); } diff --git a/src/systemColors.h b/src/systemColors.h index 62a1b1e..5deea74 100644 --- a/src/systemColors.h +++ b/src/systemColors.h @@ -6,14 +6,15 @@ #include #include +#define syscalls_SystemColors_metatable_name "syscalls SystemColors metatable" -#define syscalls_SystemColors_name "SystemColors" -#define syscalls_SystemColors_metatable_name syscalls_SystemColors_name ".mt" +int syscalls_newSystemColors(lua_State* L); -int syscalls_newSystemColors(lua_State *L); +ksys_colors_table_t* syscalls_pushSystemColors(lua_State* L); -void syscalls_pushSystemColors(lua_State *L, ksys_colors_table_t *t); - -void syscalls_register_SystemColors(lua_State *L); +/** + * Register SystemColors lib + */ +void syscalls_register_SystemColors(lua_State* L); #endif // _SYSCALLS_SYSTEMCOLORS_H_ diff --git a/tests/SystemColors.lua b/tests/SystemColors.lua new file mode 100644 index 0000000..89166e2 --- /dev/null +++ b/tests/SystemColors.lua @@ -0,0 +1,9 @@ +local syscalls = require("syscalls") + +local SystemColors = syscalls.GetSystemColors() + +print(SystemColors) + +for i, v in pairs(SystemColors) do + print(i, v) +end diff --git a/tests/libraryStruct.lua b/tests/libraryStruct.lua new file mode 100644 index 0000000..e8dcfdb --- /dev/null +++ b/tests/libraryStruct.lua @@ -0,0 +1,4 @@ + +for i, v in pairs(require("syscalls")) do + print(i, v) +end