Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "OMRuntimeExternalC"
uuid = "ada38df0-e20e-11ed-02f3-2b4b19c1ec8a"
authors = ["Adrian Pop <adrian.pop@liu.se>", "John Tinnerholm <john.tinnerholm@liu.se>"]
version = "0.3.5"
version = "0.3.6"

[deps]
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"
Expand Down
20 changes: 20 additions & 0 deletions src/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,16 @@ function ModelicaStrings_scanIdentifier(string::String, startIndex::Int64)
return (Int64(nextIndex[]), idStr)
end

#= Output-by-reference, as the Modelica external "C" declaration calls it (Modelica.Utilities.Strings
.scanToken, which MSL's readRealParameter calls). =#
function ModelicaStrings_scanIdentifier(string::AbstractString, startIndex::Integer, nextIndex::Ref{Cint},
identifier::Ref{Cstring})
ccall((:ModelicaStrings_scanIdentifier, installedLibPathlibModelicaExternalC),
Cvoid,
(Cstring, Cint, Ref{Cint}, Ref{Cstring}),
String(string), Cint(startIndex), nextIndex, identifier)
end

"""
MODELICA_EXPORT void ModelicaStrings_scanInteger(_In_z_ const char* string, int startIndex,
int unsignedNumber, int* nextIndex, int* integerNumber);
Expand Down Expand Up @@ -1051,6 +1061,16 @@ function ModelicaStrings_scanString(string::String, startIndex::Int64)
return (Int64(nextIndex[]), resStr)
end

#= Output-by-reference, as the Modelica external "C" declaration calls it (Modelica.Utilities.Strings
.scanToken, which MSL's readRealParameter calls). =#
function ModelicaStrings_scanString(string::AbstractString, startIndex::Integer, nextIndex::Ref{Cint},
result::Ref{Cstring})
ccall((:ModelicaStrings_scanString, installedLibPathlibModelicaExternalC),
Cvoid,
(Cstring, Cint, Ref{Cint}, Ref{Cstring}),
String(string), Cint(startIndex), nextIndex, result)
end

"""
MODELICA_EXPORT int ModelicaStrings_hashString(_In_z_ const char* str);
"""
Expand Down
11 changes: 11 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,17 @@ const ORC = OMRuntimeExternalC
@test nextIdx == 6
end

@testset "ModelicaStrings_scanIdentifier and scanString Ref-accepting overloads" begin
#= as the Modelica external "C" declarations call them (Strings.scanToken in MSL's readRealParameter) =#
local nextIdx = Ref{Cint}(0)
local ident = Ref{Cstring}(C_NULL)
ORC.ModelicaStrings_scanIdentifier("myVar = 42", 1, nextIdx, ident)
@test nextIdx[] == 6 && unsafe_string(ident[]) == "myVar"
local result = Ref{Cstring}(C_NULL)
ORC.ModelicaStrings_scanString(" \"abc\" rest", 1, nextIdx, result)
@test nextIdx[] == 8 && unsafe_string(result[]) == "abc"
end

@testset "ModelicaStrings_hashString" begin
#= Same string should produce the same hash =#
@test ORC.ModelicaStrings_hashString("test") == ORC.ModelicaStrings_hashString("test")
Expand Down
Loading