make working classes && add vscode config && add lua submodule

This commit is contained in:
2025-04-05 17:27:29 +05:00
parent 896579518c
commit 273e9edfc7
14 changed files with 337 additions and 241 deletions

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "lua"]
path = lua
url = https://git.kolibrios.org/lua/lua.git

23
.vscode/c_cpp_properties.json vendored Normal file
View File

@@ -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
}

8
.vscode/extensions.json vendored Normal file
View File

@@ -0,0 +1,8 @@
{
"recommendations": [
"sumneko.lua",
"ms-vscode.cpptools",
"streetsidesoftware.code-spell-checker-russian",
"streetsidesoftware.code-spell-checker"
]
}

5
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,5 @@
{
"files.associations": {
"stdlib.h": "c"
}
}

View File

@@ -6,8 +6,8 @@ STRIP=kos32-strip
OBJCOPY=kos32-objcopy OBJCOPY=kos32-objcopy
STD=-std=gnu99 STD=-std=gnu99
CFLAGS=$(SYSCFLAGS) -O2 -Wall -Wextra -DLUA_COMPAT_5_3 $(STD) $(MYCFLAGS) CFLAGS=$(SYSCFLAGS) -O2 -Wall -Wextra -DLUA_COMPAT_5_3 $(STD) $(MYCFLAGS)
LDFLAGS=$(SYSLDFLAGS) $(MYLDFLAGS) lua$(LUA_V).dll.a LDFLAGS=$(SYSLDFLAGS) $(MYLDFLAGS)
LIBS=$(SYSLIBS) $(MYLIBS) 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 TOOLCHAIN_PATH=C:/MinGW/msys/1.0/home/autobuild/tools/win32
@@ -15,13 +15,13 @@ else
TOOLCHAIN_PATH=/home/autobuild/tools/win32 TOOLCHAIN_PATH=/home/autobuild/tools/win32
endif endif
KOLIBRIOS_REPO=../../kolibrios KOLIBRIOS_REPO=../kolibrios
SDK_DIR=$(KOLIBRIOS_REPO)/contrib/sdk SDK_DIR=$(KOLIBRIOS_REPO)/contrib/sdk
NewLib_DIR=$(SDK_DIR)/sources/newlib 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 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 SYSLIBS=-nostdlib -L $(SDK_DIR)/lib -L$(TOOLCHAIN_PATH)/lib -L$(TOOLCHAIN_PATH)/mingw32/lib -lgcc -lc.dll -ldll
MYCFLAGS= MYCFLAGS=
@@ -29,15 +29,15 @@ MYLDFLAGS=
MYLIBS= MYLIBS=
MYOBJS= 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) 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: clean:
rm -f $(ALL_O) syscalls.dll rm -f $(ALL_O) syscalls.dll
src/syscalls.o: src/syscalls.c 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/ARP_entry.o: src/ARP_entry.c src/ARP_entry.h src/debug.h
src/sytemColors.o: src/sytemColors.c src/sytemColors.h src/systemColors.o: src/systemColors.c src/systemColors.h src/debug.h

1
lua Submodule

repo.diff.submodule_added%!(EXTRA template.HTML=lua, template.HTML=eae2ea0aaa)

View File

@@ -1,4 +1,5 @@
#include "ARP_entry.h" #include "ARP_entry.h"
#include "debug.h"
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
@@ -19,6 +20,8 @@ static bool syscalls_cmpAPREntry(const struct ARP_entry *entry1, const struct AR
int syscalls_indexARPEntry(lua_State* L) int syscalls_indexARPEntry(lua_State* L)
{ {
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);
@@ -52,6 +55,8 @@ int syscalls_indexARPEntry(lua_State *L)
int syscalls_newindexARPEntry(lua_State* L) int syscalls_newindexARPEntry(lua_State* L)
{ {
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);
@@ -97,17 +102,13 @@ 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); 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);
syscalls_pushARPEntry(
L,
entry);
return 1; return 1;
} }
@@ -116,27 +117,36 @@ static const luaL_Reg syscalls_ARPEntry_m[] = {
{"__newindex", syscalls_newindexARPEntry}, {"__newindex", syscalls_newindexARPEntry},
{"__eq", syscalls_eqAPREntry}, {"__eq", syscalls_eqAPREntry},
{"__gc", syscalls_gcARPEntry}, {"__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); struct ARP_entry* entry = lua_newuserdata(L, sizeof(struct ARP_entry));
luaL_setfuncs(L, syscalls_ARPEntry_m, 0);
lua_setmetatable(L, -2); luaL_setmetatable(L, syscalls_ARPEntry_metatable_name);
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");
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_newlibtable(L, syscalls_ARPEntry_m);
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);
} }

View File

@@ -22,7 +22,7 @@ struct ARP_entry
/* /*
* Create ARPEntry * 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 * shell of syscalls_createARPEntry for lua

23
src/debug.h Normal file
View File

@@ -0,0 +1,23 @@
#ifndef __DEBUG_H__
#define __DEBUG_H__
#ifdef NDEBUG
#include <sys/ksys.h>
/**
* 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__

View File

@@ -13,8 +13,11 @@
#include "scancodes.h" #include "scancodes.h"
#include "ARP_entry.h" #include "ARP_entry.h"
#include "systemColors.h" #include "systemColors.h"
/* /*
Режим ввода с клавиатуры Режим ввода с клавиатуры
@@ -158,7 +161,7 @@ static int syscalls_endRedraw(lua_State *L)
static int syscalls_SetSkin(lua_State* L) static int syscalls_SetSkin(lua_State* L)
{ {
uint ret; unsigned ret;
asm_inline( asm_inline(
"int $0x40" "int $0x40"
: "=a"(ret) : "=a"(ret)
@@ -672,12 +675,10 @@ static int syscalls_ReadPoint(lua_State *L)
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); _ksys_get_system_colors(t);
syscalls_pushSystemColors(L, t);
return 1; return 1;
} }
@@ -1641,14 +1642,12 @@ static int syscalls_ReadARPEntry(lua_State *L)
uint32_t eax; uint32_t eax;
uint8_t device = luaL_checkinteger(L, 1); uint8_t device = luaL_checkinteger(L, 1);
uint32_t entryNum = luaL_checkinteger(L, 2); uint32_t entryNum = luaL_checkinteger(L, 2);
struct ARP_entry buffer; struct ARP_entry* buffer = syscalls_pushARPEntry(L);
asm_inline( asm_inline(
"int $0x40" "int $0x40"
: "=a"(eax) : "=a"(eax)
: "a"(76), "b"((ARP << 24) | (device << 8) | 3), "c"(entryNum), "D"(&buffer)); : "a"(76), "b"((ARP << 24) | (device << 8) | 3), "c"(entryNum), "D"(buffer));
syscalls_pushARPEntry(L, &buffer);
return 1; return 1;
} }

View File

@@ -1,10 +1,14 @@
#include "systemColors.h" #include "systemColors.h"
#include "debug.h"
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
static int syscalls_SystemColors_m_index;
int syscalls_newSystemColors(lua_State* L) 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->frame_area = luaL_optinteger(L, 1, 0);
colorsTable->grab_bar = luaL_optinteger(L, 2, 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_graph = luaL_optinteger(L, 9, 0);
colorsTable->work_text = luaL_optinteger(L, 10, 0); colorsTable->work_text = luaL_optinteger(L, 10, 0);
syscalls_pushSystemColors(L, colorsTable);
return 1; return 1;
} }
static int syscalls_indexSystemColors(lua_State* L) 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 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);
@@ -150,35 +154,41 @@ static int sycalls_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)
{
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[] = { static const luaL_Reg syscalls_SystemColors_m[] = {
{"__index", syscalls_indexSystemColors}, {"__index", syscalls_indexSystemColors},
{"__newindex", syscalls_newindexSystemColors}, {"__newindex", syscalls_newindexSystemColors},
{"__eq", sycalls_eqSystemColors}, {"__eq", sycalls_eqSystemColors},
{NULL, NULL} }; {"__gc", sycalls_gcSystemColors},
{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);
}
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, 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); luaL_setfuncs(L, syscalls_SystemColors_m, 0);
lua_pop(L, 1);
} }

View File

@@ -6,14 +6,15 @@
#include <lauxlib.h> #include <lauxlib.h>
#include <sys/ksys.h> #include <sys/ksys.h>
#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);
void syscalls_pushSystemColors(lua_State *L, ksys_colors_table_t *t); ksys_colors_table_t* syscalls_pushSystemColors(lua_State* L);
/**
* Register SystemColors lib
*/
void syscalls_register_SystemColors(lua_State* L); void syscalls_register_SystemColors(lua_State* L);
#endif // _SYSCALLS_SYSTEMCOLORS_H_ #endif // _SYSCALLS_SYSTEMCOLORS_H_

9
tests/SystemColors.lua Normal file
View File

@@ -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

4
tests/libraryStruct.lua Normal file
View File

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