Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix Scala Native Example Code #3899

Merged
merged 2 commits into from
Nov 4, 2024
Merged
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
5 changes: 2 additions & 3 deletions example/scalalib/native/1-simple/src/Foo.scala
Original file line number Diff line number Diff line change
@@ -6,17 +6,16 @@ import mainargs.{main, ParserForMethods}

object Foo {

def generateHtml(text: String): CString = {
def generateHtml(text: String) (using Zone) = {
val html = "<h1>" + text + "</h1>\n"

implicit val z: Zone = Zone.open()
val cResult = toCString(html)
cResult

}

@main
def main(text: String) = {
def main(text: String) = Zone {
stdio.printf(generateHtml(text))
}

3 changes: 1 addition & 2 deletions example/scalalib/native/3-multi-module/bar/src/Bar.scala
Original file line number Diff line number Diff line change
@@ -4,9 +4,8 @@ import scala.scalanative.libc._
import scala.scalanative.unsafe._

object Bar {
def main(args: Array[String]): Unit = {
def main(args: Array[String]): Unit = Zone {
println("Running HelloWorld function")
implicit val z: Zone = Zone.open()
val result = toCString(args(0))
val barValue = HelloWorldBar.stringLength(result)
stdio.printf(c"Bar value: Argument length is %i\n", barValue)
3 changes: 1 addition & 2 deletions example/scalalib/native/3-multi-module/foo/src/Foo.scala
Original file line number Diff line number Diff line change
@@ -7,9 +7,8 @@ import mainargs.{main, ParserForMethods, arg}
object Foo {
@main
def main(@arg(name = "foo-text") fooText: String,
@arg(name = "bar-text") barText: String): Unit = {
@arg(name = "bar-text") barText: String): Unit = Zone {

implicit val z: Zone = Zone.open()
val cFooText = toCString(fooText)
val cBarText = toCString(barText)

2 changes: 1 addition & 1 deletion example/scalalib/native/4-common-config/build.mill
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ object `package` extends RootModule with ScalaNativeModule {

> ./mill run
...
Foo.value: <h1>hello</h1>
Value: <h1>hello</h1>

> ./mill show releaseMode
"mill.scalanativelib.api.ReleaseMode.ReleaseFast"
10 changes: 4 additions & 6 deletions example/scalalib/native/4-common-config/src/Foo.scala
Original file line number Diff line number Diff line change
@@ -6,18 +6,16 @@ import fansi._

object Foo {

def generateHtml(text: String): CString = {
def generateHtml(text: String) (using Zone) = {
val colored = Console.RED + "<h1>" + text + "</h1>" + Console.RESET

implicit val z: Zone = Zone.open()
val cResult = toCString(colored)
cResult
}

val value = generateHtml("hello")

def main(args: Array[String]): Unit = {
stdio.printf(c"Foo.value: %s\n", Foo.value)
def main(args: Array[String]): Unit = Zone {
val value = generateHtml("hello")
stdio.printf(c"Value: %s\n", value)
}
}

Loading