Skip to content

Commit

Permalink
Implement (uuid4)
Browse files Browse the repository at this point in the history
  • Loading branch information
da-liii committed Aug 5, 2024
1 parent 1f27786 commit a320770
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 1 deletion.
24 changes: 24 additions & 0 deletions goldfish/liii/uuid.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
;
; Copyright (C) 2024 The Goldfish Scheme Authors
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
; http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
; WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
; License for the specific language governing permissions and limitations
; under the License.
;

(define-library (liii uuid)
(export uuid4)
(begin

(define (uuid4) (g_uuid4))

) ; end of begin
) ; end of define-library
2 changes: 2 additions & 0 deletions src/goldfish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ using std::filesystem::path;

using goldfish::glue_goldfish;
using goldfish::glue_liii_os;
using goldfish::glue_liii_uuid;
using goldfish::glue_scheme_process_context;
using goldfish::glue_scheme_time;

Expand Down Expand Up @@ -107,6 +108,7 @@ main (int argc, char** argv) {
glue_scheme_time (sc);
glue_scheme_process_context (sc);
glue_liii_os (sc);
glue_liii_uuid (sc);

// Command options
vector<string> args (argv + 1, argv + argc);
Expand Down
17 changes: 17 additions & 0 deletions src/goldfish.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,21 @@ glue_liii_os (s7_scheme* sc) {
d_os_call, NULL));
}

static s7_pointer
f_uuid4 (s7_scheme* sc, s7_pointer args) {
tb_char_t uuid[37];
const tb_char_t* ret= tb_uuid4_make_cstr (uuid, tb_null);
return s7_make_string (sc, ret);
}

inline void
glue_liii_uuid (s7_scheme* sc) {
s7_pointer cur_env= s7_curlet (sc);
const char* s_uuid4= "g_uuid4";
const char* d_uuid4= "(g_uuid4) => string";
s7_define (sc, cur_env, s7_make_symbol (sc, s_uuid4),
s7_make_typed_function (sc, s_uuid4, f_uuid4, 0, 0, false, d_uuid4,
NULL));
}

} // namespace goldfish
25 changes: 25 additions & 0 deletions tests/liii/uuid-test.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
;
; Copyright (C) 2024 The Goldfish Scheme Authors
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
; http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
; WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
; License for the specific language governing permissions and limitations
; under the License.
;

(import (srfi srfi-78)
(liii uuid))

(check-set-mode! 'report-failed)

(check (string-length (uuid4)) => 36)

(check-report)
(if (check-failed?) (exit -1))
2 changes: 1 addition & 1 deletion xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ local S7_VERSION = "20240702"
add_requires("s7 "..S7_VERSION, {system=false})

local TBOX_VERSION = "1.7.5"
tbox_configs = {["force-utf8"]=true}
tbox_configs = {hash=true, ["force-utf8"]=true}
add_requires("tbox " .. TBOX_VERSION, {system=false, configs=tbox_configs})

target ("goldfish") do
Expand Down

0 comments on commit a320770

Please sign in to comment.