paranim / pararules

A Nim rules engine
The Unlicense
139 stars 3 forks source link

Proper way to split project into multiple files #6

Closed arkanoid87 closed 1 year ago

arkanoid87 commented 1 year ago

Been trying to split elements in different modules for proper management:

but exporting a ruleset fails to iterate in other modules "Error: undeclared identifier: 'fields'"

I've been trying with templates to move thing around, but it's like a cannon for ants. What would you suggest?

Thanks

oakes commented 1 year ago

Hmm, are you sure the exported variable isn't being shadowed by something? I just tried the following in the parakeet project and it worked:

parakeet % git diff
diff --git a/src/core.nim b/src/core.nim
index 1ac09b2..f4af50b 100644
--- a/src/core.nim
+++ b/src/core.nim
@@ -67,7 +67,7 @@ proc decelerate(velocity: float): float =
   let v = velocity * deceleration
   if abs(v) < damping: 0f else: v

-let (initSession, rules) =
+let (initSession*, rules*) =
   staticRuleset(Fact, FactMatch):
     # getters
     rule getWindow(Fact):
diff --git a/src/parakeet.nim b/src/parakeet.nim
index afbe7d8..ad7245d 100644
--- a/src/parakeet.nim
+++ b/src/parakeet.nim
@@ -1,6 +1,12 @@
 import paranim/glfw
 import core

+# make sure we can make a session from another module
+import pararules
+var session: Session[Fact, FactMatch] = initSession(autoFire = false)
+for r in rules.fields:
+  session.add(r)
+
 when defined(paravim):
   from paravim import nil
   var focusOnGame = true
arkanoid87 commented 1 year ago

I've found what was blocking me

let (initSession, rules) = staticRuleset() vs const (initSession, rules) = staticRuleset()

oakes commented 1 year ago

Ah yep that will do it.

arkanoid87 commented 1 year ago

thanks!