nested-structs/arrays (C)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 28/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Cần làm rõ
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- c, javascript
- Lĩnh vực
- tooling
Hướng nghiên cứu
Bắt đầu với tools/gen_lib.js, quanh vòng lặp tạo struct, và xem xét các trường struct trong api.json, đặc biệt là các kiểu mảng và struct lồng nhau hiện đang bị bỏ qua. Trước tiên hãy kiểm tra issue #9, sau đó kiểm tra src/structs.h và src/lib.c được tạo; hoàn thành có nghĩa là các trường đó không còn bị âm thầm bỏ qua khỏi các tiện ích được tạo nữa.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I am currently skipping these in C codegen. They should be addressed, once I figure out #9
https://github.com/konsumer/raylib-pointers/blob/f365325/tools/gen_lib.js#L22
// this will generate raylib-pointers
import { writeFile } from 'fs/promises'
import api from './api.json'
const { structs, wrapped } = api
let out = []
// build utils for structs
for (const { name, description, fields } of structs) {
out.push(`// ${description}
unsigned int ${name}_size() {
return sizeof(${name});
}`)
for (const field of fields) {
if (field.type.includes('[')) {
// TODO: add utils for arrays
} else if (/^[A-Z]/.test(field.type)) {
// cheap way to detect raylib types
// TODO: add utils for nested structs
} else {
out.push(`${field.type} ${name}_get_${field.name}(${name}* p) {\n return p->${field.name};\n}`)
out.push(`void ${name}_set_${field.name}(${name}* p, ${field.type} v) {\n p->${field.name} = v;\n}`)
}
}
out.push('')
}
await writeFile('src/structs.h', out.join('\n'))
out = [
`#include <stdlib.h>
#include "raylib.h"
// utils for operating on structs
#include "./structs.h"
// this allows us to free anything that was allocated, last-frame
// max number of allocations you can do, per-frame
#define FRAME_ALLOC_SIZE 1024*512
int _frame_alloc_counter = 0;
void* _frame_allocated[FRAME_ALLOC_SIZE] = {};
bool running = false;
void* wrapped_alloc(size_t s) {
void* p = RL_MALLOC(s);
if (running) {
_frame_allocated[_frame_alloc_counter] = p;
_frame_alloc_counter = (_frame_alloc_counter + 1) % FRAME_ALLOC_SIZE;
}
return p;
}
void wrapped_free(void* p) {
RL_FREE(p);
}
bool wrapped_WindowShouldClose() {
running = true;
for (int i=0;i<_frame_alloc_counter;i++) {
wrapped_free(_frame_allocated[i]);
}
_frame_alloc_counter = 0;
return WindowShouldClose();
}
`
]
// these will not be ghenerated for
const blocklist = [
// I will be implementing my own mem-management stuff
'wrapped_WindowShouldClose',
'wrapped_free',
'wrapped_alloc'
]
for (const { name, description, returnType, params, original } of wrapped) {
if (blocklist.includes(name)) {
continue
}
// does return need to be converted to a pointer?
const returnPointer = /^[A-Z]/.test(returnType)
// do any params need to be converted to pointers?
let paramPointer = false
const inputParams = params.map((p) => {
if (/^[A-Z]/.test(p.type)) {
paramPointer = true
return `${p.type.trim()} ${p.name}`
} else {
return `${p.type} ${p.name}`
}
})
const callParams = params.map((p) => {
if (/^[A-Z]/.test(p.type)) {
paramPointer = true
return `*${p.name}`
} else {
return p.name
}
})
out.push(`// ${description}`)
if (returnPointer) {
out.push(`${returnType} ${name}(${inputParams.join(', ')}) {`)
out.push(` ${returnType} _ret = wrapped_alloc(sizeof(${returnType.replace('*', '')}));`)
out.push(` *_ret = ${original}(${callParams.join(', ')});`)
out.push(' return _ret;')
} else {
out.push(`${returnType} ${name}(${inputParams.join(', ')}) {`)
if (returnType === 'void') {
out.push(` ${original}(${callParams.join(', ')});`)
} else {
out.push(` return ${original}(${callParams.join(', ')});`)
}
}
out.push('}\n')
}
await writeFile('src/lib.c', out.join('\n'))
- Ngôn ngữ chính
- C
- Star
- 0
- Fork
- 1
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của konsumer/raylib-pointers
-
Potential memory leakĐang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
konsumer/raylib-pointers#12 · 2 bình luận · 1 reaction ·
-
Nested structs & arraysĐang mởenhancement parent
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
-
defines (bun)Đang mởbunjs enhancement todo
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 48/100
-
nested structs (bun)Đang mởbunjs enhancement todo
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
-
bunjs enhancement todo
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
Tất cả issue của konsumer/raylib-pointers
Issue tương tự
-
Implement looks_size reporterĐang mởenhancement good first issue help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
bug multiplayer status: planned
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
ChupathingyCE/chupathingyce#851 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
HigherOrderCO/Bend#2104 ·
-
Research radar digest 2026-W46Đang mởresearch-radar
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
good first issue help wanted program
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
hffgzktbcc-blip/ounce-core#297 ·
Maintainer thường phản hồi trong vòng 1 ngày