edubart / nelua-lang

Minimal, efficient, statically-typed and meta-programmable systems programming language heavily inspired by Lua, which compiles to C and native code.
https://nelua.io
MIT License
1.99k stars 64 forks source link

how use Wx in nelua? #210

Closed MillhioreBT closed 1 year ago

MillhioreBT commented 1 year ago

Hello, I had never tried this programming language, although I saw it a long time ago, today I wanted to try it and I would like to know if it is possible and how to use Wx to create a graphical interface and create a calculator or some window program for example.

I was reading the documentation a bit and looking at some examples, but I don't see enough information about it, I don't quite understand the language either, it's my first day

This is what I was trying but there seems to be a error:

##[[
    cflags "-I/mingw64/include -I/mingw64/include/wx-3.0"
    ldflags "-L/mingw64/lib"
]]

require("string")
require("memory")
require("allocators.default")

local wxApp <cimport> = @record{}
local wxFrame <cimport> = @record{}

local app: *wxApp = default_allocator:new(@wxApp)

app = nilptr

error:

$ nelua examples/helloworld.nelua
gc.nelua:759:16: runtime error: out of memory
    assert(ptr ~= nilptr, 'out of memory')
               ^~~~~~~~~

probably what I did does not make sense, but could someone guide me?

stefanos82 commented 1 year ago

You are allocating memory, but you are not deallocating it, in other words free()-ing it.

Try default_allocator:delete(app) in place of app = nilptr and see how it behaves.

By the way, I don't know how to call a C++ project in Nelua; the only examples I have seen so far are in C.

Maybe @edubart could jump in and enlighten both of us here?

edubart commented 1 year ago

This was actually a misuse that triggered a bug.

You were importing a C struct without filling its fields, so the record ended up with size 0. And new was not prepared to work with empty records (where size is 0), generating the misleading message out of memory. I fixed this in a recent commit.