EventList and Spline do not seem to be defined (api)

未关闭
#1 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
c, javascript
领域
api, build-system

调研方向

从 tools/gen_api.js 以及 EventList 和 Spline 的 blocklist 条目开始,然后检查 build/_deps/raylib-src/parser/output/raylib_api.json 和生成的 tools/api.json。将生成的声明与 DLL FFI wrapper 使用的 raylib 版本进行比较。当受影响的 API 条目与可用的 raylib 符号匹配,并且不再产生未定义函数错误时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

api bug todo

Essentially, all the functions with EventList or Spline are not defined (but are output by raylib api-gen) and throw an error if DLL is ffi-wrapped.

I think this is related to versioning mismatch with raylib (which may be a sign I need to adjust build to use raylib better.)

https://github.com/konsumer/raylib-pointers/blob/f365325/tools/gen_api.js#L27


// this will generate API info about all the new wrapped stuff & utils
// it's basically the same as the stuff parser generates in raylib
// but I add my wrappers and and struct-utils

import { writeFile, readFile } from 'fs/promises'

// check if the function will be wrapped
const isWrapped = (f) => {
  const returnPointer = /^[A-Z]/.test(f.returnType)

  // do any params need to be converted to pointers?
  let paramPointer = false

  for (const p of f.params || []) {
    if (/[A-Z]/.test(p.type)) {
      paramPointer = true
      break
    }
  }
  return returnPointer || paramPointer
}

export const blocklist = [
  // this is blocked because I add wrapped_WindowShouldClose manually
  'WindowShouldClose',

  // TODO: I think these are not available in the current version, but for some reason are referenced
  'LoadAutomationEventList',
  'UnloadAutomationEventList',
  'ExportAutomationEventList',
  'SetAutomationEventList',
  'PlayAutomationEventList',
  'PlayAutomationEvent',
  'DrawLineBezier',
  'DrawCircleLinesV',
  'DrawSplineLinear',
  'DrawSplineBasis',
  'DrawSplineCatmullRom',
  'DrawSplineBezierQuadratic',
  'DrawSplineBezierCubic',
  'DrawSplineSegmentLinear',
  'DrawSplineSegmentBasis',
  'DrawSplineSegmentCatmullRom',
  'DrawSplineSegmentBezierQuadratic',
  'DrawSplineSegmentBezierCubic',
  'GetSplinePointLinear',
  'GetSplinePointBasis',
  'GetSplinePointCatmullRom',
  'GetSplinePointBezierQuad',
  'GetSplinePointBezierCubic'
]

const blocklistStructs = []

const { defines, structs, aliases, enums, callbacks, functions } = JSON.parse(await readFile('build/_deps/raylib-src/parser/output/raylib_api.json'))

const wrapped = []
const unwrapped = []
const struct_utils = []

for (const { name, description, fields } of structs) {
  if (blocklistStructs.includes(name)) {
    continue
  }

  struct_utils.push({
    name: `${name}_size`,
    description: `Get byte-size of ${name} struct`,
    returnType: 'unsigned int',
    params: []
  })
  for (const field of fields) {
    struct_utils.push({
      name: `${name}_get_${field.name}`,
      description: `Getter for ${name}->${field.name}`,
      returnType: field.type,
      params: [{ name: 'obj', type: `${field.name}*` }]
    })
    struct_utils.push({
      name: `${name}_set_${field.name}`,
      description: `Setter for ${name}->${field.name}`,
      returnType: 'void',
      params: [
        { name: 'obj', type: `${field.name}*` },
        { name: 'v', type: field.type }
      ]
    })
  }
}

for (const f of functions) {
  if (blocklist.includes(f.name)) {
    continue
  }
  if (isWrapped(f)) {
    wrapped.push({
      name: `wrapped_${f.name}`,
      description: f.description,
      original: f.name,
      returnType: /[A-Z]/.test(f.returnType) ? `${f.returnType}*` : f.returnType,
      params: (f.params || []).map((p) => {
        return {
          ...p,
          type: /[A-Z]/.test(p.type) ? `${p.type}*` : p.type
        }
      })
    })
  } else {
    f.params ||= []
    unwrapped.push(f)
  }
}

// these are my additions (per-frame alloc/free)

wrapped.push({
  name: 'wrapped_alloc',
  original: 'alloc',
  description: 'Allocate memory, cleared on every WindowShouldClose call (your frame update-loop)',
  returnType: 'void*',
  params: [
    {
      name: 'size',
      type: 'unsigned int',
      description: 'The size (in bytes) to allocate'
    }
  ]
})

wrapped.push({
  name: 'wrapped_free',
  original: 'free',
  description: 'Clear allocated memory. If it was not allocated (or has already been freed) this will error.',
  returnType: 'void',
  params: [
    {
      name: 'pointer',
      type: 'void*',
      description: 'The pointer to free'
    }
  ]
})

wrapped.push({
  name: 'wrapped_WindowShouldClose',
  original: 'WindowShouldClose',
  description: 'Check if application should close (KEY_ESCAPE pressed or windows close icon clicked.) This also clears memory that was allocated since last call.',
  returnType: 'bool',
  params: []
})

await writeFile('tools/api.json', JSON.stringify({ unwrapped, wrapped, struct_utils, defines, structs, aliases, enums, callbacks, functions }, null, 2))

主要语言
C
星标
0
派生
1
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

konsumer/raylib-pointers 的其他 Issue

查看 konsumer/raylib-pointers 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。