Added nuklear example. Demo isnt quite right. its a huge example.

This commit is contained in:
David Lannan 2024-10-11 00:16:58 +10:30
parent f834099a9a
commit 8dc5a00d59
20 changed files with 10384 additions and 2 deletions

BIN
bin/linux/libjpeg.so Normal file

Binary file not shown.

BIN
bin/linux/libuv.so Normal file

Binary file not shown.

BIN
bin/linux/luajit Normal file

Binary file not shown.

BIN
bin/macos/png.dylib Normal file

Binary file not shown.

Binary file not shown.

BIN
bin/win64/libuv.dll Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

86
examples/libuv/test.lua Normal file
View File

@ -0,0 +1,86 @@
package.path = package.path..";lua/?.lua;lua/?/init.lua"
package.path = package.path..";ffi/?.lua;ffi/?/init.lua"
package.path = package.path..";deps/?.lua;deps/?/init.lua"
-----------------------------------------------------------------------------------------------
local ffi = require 'ffi'
local ffiext = require 'ffi-extensions'
local p = require 'pretty-print-ffi'.prettyPrint
local loop = require 'uv-ffi'
local function makeHeader(datalen)
local dt = os.date("%a, %d %b %Y %X GMT")
local data = "HTTP/1.1 200 OK\r\n"..
"Date: "..dt.."\r\n"..
"Server: Apache/2.4.29 (Ubuntu)\r\n"..
"Cache-Control: max-age=604800\r\n"..
"Pragma: no-cache\r\n"..
"Content-Encoding: none\r\n"..
"Content-Length: "..datalen.."\r\n"..
"Connection: Close\r\n"..
"Content-Type: text/html;charset=UTF-8\r\n\r\n"
return data
end
-- require 'safe-coro'(function ()
-- local timer = loop:newTimer()
-- p("About to sleep", timer)
-- timer:sleep(1000)
-- p("Done sleeping!", timer)
-- timer:close()
-- end)
local function alloc_buffer(handle, suggested_size)
return loop.uv.uv_buf_init( ffi.new("char[?]", suggested_size), suggested_size)
end
local function echo_write(req, status)
if status == -1 then
p("Write error!")
end
p("Request:", req)
end
local function echo_read(client, nread, buf)
if nread == -1 then
p("Read error!");
loop.uv.uv_close(ffi.cast("uv_handle_t*",client), nil)
return
end
local write_req = ffi.new("uv_write_t[1]")
local data = ffi.new ("uv_buf_t[1]")
local resp = "<h1>HELLOOOOO</h1>\r\n"
local hdr = makeHeader(#resp)
hdr = hdr..resp
data[0].base = ffi.cast("char *", hdr)
data[0].len = #hdr
loop.uv.uv_write(write_req, client, data, 1, echo_write)
end
function on_new_connect( server, status )
client = ffi.new("uv_tcp_t[1]")
loop.uv.uv_tcp_init(loop, client)
-- Start accepting the request
if loop.uv.uv_accept(server, ffi.cast("uv_stream_t*", client)) == 0 then
-- Valid accept then start reading stream
loop.uv.uv_read_start(ffi.cast("uv_stream_t*", client), alloc_buffer, echo_read)
else
-- Bad request or connection closed
loop.uv.uv_close(ffi.cast("uv_handle_t*",client), nil)
end
end
local server = loop:newTcp()
local res = loop:bind(server, "0.0.0.0", 7000)
runcb = server:listen( 128, on_new_connect )
if runcb == nil then p("Couldnt create server."); return end
loop:run('default')

View File

@ -0,0 +1,55 @@
package.path = package.path..";lua/?.lua;lua/?/init.lua"
package.path = package.path..";ffi/?.lua;ffi/?/init.lua"
package.path = package.path..";deps/?.lua;deps/?/init.lua"
-----------------------------------------------------------------------------------------------
local ffi = require 'ffi'
local ffiext = require 'ffi-extensions'
local kern = ffiext.kern
local p = require 'pretty-print-ffi'.prettyPrint
local loop = require 'uv-ffi'
-----------------------------------------------------------------------------------------------
function hare(arg)
local tracklen = arg[0]
while (tracklen) do
tracklen = tracklen - 1
kern.Sleep(100)
p("Hare ran another step.")
end
end
-----------------------------------------------------------------------------------------------
function tortoise(arg)
local tracklen = arg[0]
while (tracklen) do
tracklen = tracklen - 1
kern.Sleep(500)
p("Tortise ran another step.")
end
end
-----------------------------------------------------------------------------------------------
local tracklen1 = ffi.new("int[1]", 10)
local tracklen2 = ffi.new("int[1]", 10)
local hare_id = ffi.new("uv_thread_t[1]")
local tortoise_id = ffi.new("uv_thread_t[1]")
local id1 = loop.uv.uv_thread_create(hare_id, hare, tracklen1)
local id2 = loop.uv.uv_thread_create(tortoise_id, tortoise, tracklen2)
p("Res:", id1)
p("Res:", id2)
while tracklen2[0] > 0 do
kern.Sleep(50)
end
loop.uv.uv_thread_join(hare_id)
loop.uv.uv_thread_join(tortoise_id)
-----------------------------------------------------------------------------------------------

Binary file not shown.

View File

@ -4,7 +4,7 @@ package.path = package.path..";../?.lua"
--_G.SOKOL_DLL = "sokol_debug_dll"
local sapp = require("sokol_app")
local sg = require("sokol_imgui") -- Includes gfx!!
sg = require("sokol_imgui") -- Includes gfx!!
local im = sg -- Will NOT be using imgui in applications. Sample only. Dont recommend.
local slib = require("sokol_libs") -- Warn - always after gfx!!

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
local sg = _G.sg
local sg = _G.sg or require("sokol_gfx")
local hmm_utils = {}

7694
ffi/sokol/sokol_nuklear.lua Normal file

File diff suppressed because it is too large Load Diff

1072
ffi/uv-ffi.lua Normal file

File diff suppressed because it is too large Load Diff