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

1
lua Submodule

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

View File

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

View File

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

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__

File diff suppressed because it is too large Load Diff

View File

@@ -1,10 +1,14 @@
#include "systemColors.h"
#include "debug.h"
#include <string.h>
#include <stdlib.h>
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);
}

View File

@@ -6,14 +6,15 @@
#include <lauxlib.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);
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_

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