packages feed

fresco-binding 0.1.1 → 0.2.0

raw patch · 5 files changed

+204/−41 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Fresco.System: [cbsfCreate] :: EntityInterface -> CallbackSystemCreateFunction
- Fresco.System: [cbsfRegisterReceiver] :: EntityInterface -> CallbackSystemRegisterReceiverFunction
- Fresco.System: [cbsfStep] :: EntityInterface -> CallbackSystemStepFunction
- Fresco.System: [efCreate] :: EntityInterface -> EntityCreateFunction
- Fresco.System: [efSet] :: EntityInterface -> EntitySetFunction
+ Fresco.Component: instance Fresco.Component.ComponentClass Data.ByteString.Internal.ByteString
+ Fresco.Entity: ObjectLibSystem :: (Ptr ()) -> ObjectLibSystem
+ Fresco.Entity: addEntityOLS :: ObjectLibSystem -> Entity -> IO ()
+ Fresco.Entity: createOLS :: IO ObjectLibSystem
+ Fresco.Entity: data ObjectLibSystem
+ Fresco.Entity: delE :: Entity -> IO ()
+ Fresco.Entity: idE :: Entity -> IO ByteString
+ Fresco.Entity: stepOLS :: ObjectLibSystem -> IO ()
+ Fresco.System: [cbsCreate] :: EntityInterface -> CallbackSystemCreateFunction
+ Fresco.System: [cbsRegisterReceiver] :: EntityInterface -> CallbackSystemRegisterReceiverFunction
+ Fresco.System: [cbsStep] :: EntityInterface -> CallbackSystemStepFunction
+ Fresco.System: [eCreate] :: EntityInterface -> EntityCreateFunction
+ Fresco.System: [eDestroy] :: EntityInterface -> EntityDestroyFunction
+ Fresco.System: [eIdFree] :: EntityInterface -> EntityIdFreeFunction
+ Fresco.System: [eId] :: EntityInterface -> EntityIdFunction
+ Fresco.System: [edSet] :: EntityInterface -> EntitySetFunction
+ Fresco.System: [olsAddEntity] :: EntityInterface -> ObjectLibSystemAddEntityFunction
+ Fresco.System: [olsCreate] :: EntityInterface -> ObjectLibSystemCreateFunction
+ Fresco.System: [olsStep] :: EntityInterface -> ObjectLibSystemStepFunction
+ Fresco.System: entityDestroy :: Ptr () -> IO ()
+ Fresco.System: entityId :: Ptr () -> IO ByteString
+ Fresco.System: mkEntityDestroyFunction :: FunPtr EntityDestroyFunction -> EntityDestroyFunction
+ Fresco.System: mkEntityIdFreeFunction :: FunPtr EntityIdFreeFunction -> EntityIdFreeFunction
+ Fresco.System: mkEntityIdFunction :: FunPtr EntityIdFunction -> EntityIdFunction
+ Fresco.System: mkObjectLibSystemAddEntityFunction :: FunPtr ObjectLibSystemAddEntityFunction -> ObjectLibSystemAddEntityFunction
+ Fresco.System: mkObjectLibSystemCreateFunction :: FunPtr ObjectLibSystemCreateFunction -> ObjectLibSystemCreateFunction
+ Fresco.System: mkObjectLibSystemStepFunction :: FunPtr ObjectLibSystemStepFunction -> ObjectLibSystemStepFunction
+ Fresco.System: objectLibSystemAddEntity :: (Ptr ()) -> (Ptr ()) -> IO ()
+ Fresco.System: objectLibSystemCreate :: IO ((Ptr ()))
+ Fresco.System: objectLibSystemStep :: (Ptr ()) -> IO ()
+ Fresco.System: type EntityDestroyFunction = (Ptr ()) -> IO ()
+ Fresco.System: type EntityIdFreeFunction = (Ptr CChar) -> IO ()
+ Fresco.System: type EntityIdFunction = (Ptr ()) -> IO (Ptr CChar)
+ Fresco.System: type ObjectLibSystemAddEntityFunction = (Ptr ()) -> ((Ptr ()) -> (IO ()))
+ Fresco.System: type ObjectLibSystemCreateFunction = (Ptr (Ptr ())) -> (IO ())
+ Fresco.System: type ObjectLibSystemStepFunction = (Ptr ()) -> (IO ())
- Fresco.System: EntityInterface :: EntityCreateFunction -> EntitySetFunction -> CallbackSystemCreateFunction -> CallbackSystemRegisterReceiverFunction -> CallbackSystemStepFunction -> EntityGetDataFunction -> EntityDataReadFunction -> EntityDataReleaseFunction -> EntityInterface
+ Fresco.System: EntityInterface :: EntityCreateFunction -> EntityDestroyFunction -> EntityIdFunction -> EntityIdFreeFunction -> EntitySetFunction -> EntityGetDataFunction -> EntityDataReadFunction -> EntityDataReleaseFunction -> ObjectLibSystemCreateFunction -> ObjectLibSystemAddEntityFunction -> ObjectLibSystemStepFunction -> CallbackSystemCreateFunction -> CallbackSystemRegisterReceiverFunction -> CallbackSystemStepFunction -> EntityInterface

Files

Fresco/Component.hs view
@@ -57,6 +57,10 @@     toObj i = ObjectInt (fromIntegral i)     fromObj (ObjectInt i) = fromIntegral i     +instance ComponentClass ByteString where+    toObj bs = ObjectString bs+    fromObj (ObjectString bs) = bs+ instance ComponentClass a => ComponentClass (Maybe a) where     toObj Nothing = ObjectArray [ObjectInt 0]     toObj (Just v) = ObjectArray [ObjectInt 1, toObj v]
Fresco/Entity.hs view
@@ -30,12 +30,20 @@    Entity (..),   newE,+  delE,+  idE,+  -- readE,   readC,   updateC,   setC,  -- _setC', + ObjectLibSystem (..),+ createOLS,+ stepOLS,+ addEntityOLS,+  CallbackSystem (..),  createCBS,  stepCBS,@@ -116,6 +124,19 @@   callbackSystemRegisterReceiver cbs ep ct mf   return () +data ObjectLibSystem = ObjectLibSystem (Ptr ())++createOLS :: IO ObjectLibSystem+createOLS = do +  ols <- objectLibSystemCreate+  return $ ObjectLibSystem ols++stepOLS :: ObjectLibSystem -> IO ()+stepOLS (ObjectLibSystem ols) = objectLibSystemStep ols++addEntityOLS :: ObjectLibSystem -> Entity -> IO ()+addEntityOLS (ObjectLibSystem ols) (Entity ep) = objectLibSystemAddEntity ols ep+ -- References to Entities  -- besides Entity, we need atomic references to entities, we call them ERef@@ -146,6 +167,14 @@      let e = entityData inlist      ep <- entityCreate (msgFromE e)      return $ Entity ep++-- | destroys an Entity+delE :: Entity -> IO ()+delE (Entity ep) = entityDestroy ep++-- | gets id of an Entity+idE :: Entity -> IO ByteString+idE (Entity ep) = entityId ep  -- | reads one ComponentType, throws exception, if ComponentType not present, or wrong type readC :: ComponentClass a => Entity -> ComponentType a -> IO a
Fresco/System.hs view
@@ -18,7 +18,6 @@  import Data.ByteString import Data.ByteString.Unsafe-import qualified Data.ByteString.Lazy as BL import Data.MessagePack import Data.Either import Data.Maybe@@ -82,6 +81,19 @@ foreign import ccall "dynamic"     mkEntityCreateFunction :: FunPtr EntityCreateFunction -> EntityCreateFunction +type EntityDestroyFunction = ((Ptr ()) -> IO ()) +foreign import ccall "dynamic" +   mkEntityDestroyFunction :: FunPtr EntityDestroyFunction -> EntityDestroyFunction++type EntityIdFunction = ((Ptr ()) -> IO (Ptr CChar))+foreign import ccall "dynamic"+  mkEntityIdFunction :: FunPtr EntityIdFunction -> EntityIdFunction++type EntityIdFreeFunction = ((Ptr CChar) -> IO ())+foreign import ccall "dynamic"+  mkEntityIdFreeFunction :: FunPtr EntityIdFreeFunction -> EntityIdFreeFunction++ type EntitySetFunction = ((Ptr CChar) -> (Word32 -> ((Ptr ()) -> (IO ())))) foreign import ccall "dynamic"     mkEntitySetFunction :: FunPtr EntitySetFunction -> EntitySetFunction@@ -102,7 +114,23 @@    mkEntityDataReleaseFunction :: FunPtr EntityDataReleaseFunction -> EntityDataReleaseFunction  +-- pub extern "C" fn callback_system_create(pp: *mut *mut CallbackSystem) {+type ObjectLibSystemCreateFunction = ((Ptr (Ptr ())) -> (IO ()))+foreign import ccall "dynamic" +   mkObjectLibSystemCreateFunction :: FunPtr ObjectLibSystemCreateFunction -> ObjectLibSystemCreateFunction +-- pub extern "C" fn callback_system_step(cbs: *mut CallbackSystem) {+type ObjectLibSystemAddEntityFunction = ((Ptr ()) -> ((Ptr ()) -> (IO ())))+foreign import ccall "dynamic" +   mkObjectLibSystemAddEntityFunction:: FunPtr ObjectLibSystemAddEntityFunction -> ObjectLibSystemAddEntityFunction+   +-- pub extern "C" fn callback_system_step(cbs: *mut CallbackSystem) {+type ObjectLibSystemStepFunction = ((Ptr ()) -> (IO ()))+foreign import ccall "dynamic" +   mkObjectLibSystemStepFunction:: FunPtr ObjectLibSystemStepFunction -> ObjectLibSystemStepFunction+   ++ -- pub extern "C" fn callback_system_create(pp: *mut *mut CallbackSystem) { type CallbackSystemCreateFunction = ((Ptr (Ptr ())) -> (IO ())) foreign import ccall "dynamic" @@ -117,16 +145,26 @@ type CallbackSystemStepFunction = ((Ptr ()) -> (IO ())) foreign import ccall "dynamic"     mkCallbackSystemStepFunction:: FunPtr CallbackSystemStepFunction -> CallbackSystemStepFunction+     data EntityInterface = EntityInterface {-                        efCreate :: EntityCreateFunction,-                        efSet :: EntitySetFunction,-                        cbsfCreate :: CallbackSystemCreateFunction,-                        cbsfRegisterReceiver :: CallbackSystemRegisterReceiverFunction,-                        cbsfStep :: CallbackSystemStepFunction,+                        eCreate :: EntityCreateFunction,+                        eDestroy :: EntityDestroyFunction,+                        eId :: EntityIdFunction,+                        eIdFree :: EntityIdFreeFunction,++                        edSet :: EntitySetFunction,                         edGet :: EntityGetDataFunction,                         edRead :: EntityDataReadFunction,-                        edRelease :: EntityDataReleaseFunction+                        edRelease :: EntityDataReleaseFunction,++                        olsCreate :: ObjectLibSystemCreateFunction,+                        olsAddEntity :: ObjectLibSystemAddEntityFunction,+                        olsStep :: ObjectLibSystemStepFunction,++                        cbsCreate :: CallbackSystemCreateFunction,+                        cbsRegisterReceiver :: CallbackSystemRegisterReceiverFunction,+                        cbsStep :: CallbackSystemStepFunction                       }  #ifdef UseWinDLLLoading@@ -136,31 +174,53 @@     libname <- getEnv "INTONACO"     dll <- loadLibrary libname -    efc <- getProcAddress dll "entity_create"-    let efc' = mkEntityCreateFunction $ castPtrToFunPtr efc+    ec <- getProcAddress dll "entity_create"+    let ec' = mkEntityCreateFunction $ castPtrToFunPtr ec -    efs <- getProcAddress dll "entity_set" -    let efs' = mkEntitySetFunction $ castPtrToFunPtr efs+    ed <- getProcAddress dll "entity_destroy"+    let ed' = mkEntityDestroyFunction $ castPtrToFunPtr ed -    cbc <- getProcAddress dll "callback_system_create" -    let cbc' = mkCallbackSystemCreateFunction $ castPtrToFunPtr cbc+    ei <- getProcAddress dll "entity_id"+    let ei' = mkEntityIdFunction $ castPtrToFunPtr ei -    cbr <- getProcAddress dll "callback_system_register_receiver" -    let cbr' = mkCallbackSystemRegisterReceiverFunction $ castPtrToFunPtr cbr+    eif <- getProcAddress dll "entity_id_free"+    let eif' = mkEntityIdFreeFunction $ castPtrToFunPtr eif -    cbs <- getProcAddress dll "callback_system_step" -    let cbs' = mkCallbackSystemStepFunction $ castPtrToFunPtr cbs +    eds <- getProcAddress dll "entity_set" +    let eds' = mkEntitySetFunction $ castPtrToFunPtr eds+     edg <- getProcAddress dll "entity_get_data"     let edg' = mkEntityGetDataFunction $ castPtrToFunPtr edg      edr <- getProcAddress dll "entity_data_read"     let edr' = mkEntityDataReadFunction $ castPtrToFunPtr edr -    edd <- getProcAddress dll "entity_data_release"-    let edd' = mkEntityDataReleaseFunction $ castPtrToFunPtr edd+    edrl <- getProcAddress dll "entity_data_release"+    let edrl' = mkEntityDataReleaseFunction $ castPtrToFunPtr edrl -    ref <- newIORef $ EntityInterface efc' efs' cbc' cbr' cbs' edg' edr' edd'++    olc <- getProcAddress dll "object_lib_system_create" +    let olc' = mkObjectLibSystemCreateFunction $ castPtrToFunPtr olc++    ola <- getProcAddress dll "object_lib_system_add_entity" +    let ola' = mkObjectLibSystemAddEntityFunction $ castPtrToFunPtr ola++    ols <- getProcAddress dll "object_lib_system_step" +    let ols' = mkObjectLibSystemStepFunction $ castPtrToFunPtr ols+++    cbc <- getProcAddress dll "callback_system_create" +    let cbc' = mkCallbackSystemCreateFunction $ castPtrToFunPtr cbc++    cbr <- getProcAddress dll "callback_system_register_receiver" +    let cbr' = mkCallbackSystemRegisterReceiverFunction $ castPtrToFunPtr cbr++    cbs <- getProcAddress dll "callback_system_step" +    let cbs' = mkCallbackSystemStepFunction $ castPtrToFunPtr cbs+++    ref <- newIORef $ EntityInterface ec' ed' ei' eif'  eds' edg' edr' edrl'  olc' ola' ols'  cbc' cbr' cbs'      return ref     ) @@ -174,31 +234,53 @@     libname <- getEnv "INTONACO"     dll <- dlopen libname [RTLD_NOW] -    efc <- dlsym dll "entity_create"-    let efc' = mkEntityCreateFunction efc+    ec <- dlsym dll "entity_create"+    let ec' = mkEntityCreateFunction ec -    efs <- dlsym dll "entity_set" -    let efs' = mkEntitySetFunction efs+    ed <- dlsym dll "entity_destroy"+    let ed' = mkEntityDestroyFunction ed -    cbc <- dlsym dll "callback_system_create" -    let cbc' = mkCallbackSystemCreateFunction cbc+    ei <- dlsym dll "entity_id"+    let ei' = mkEntityIdFunction ei -    cbr <- dlsym dll "callback_system_register_receiver" -    let cbr' = mkCallbackSystemRegisterReceiverFunction cbr+    eif <- dlsym dll "entity_id_free"+    let eif' = mkEntityIdFreeFunction eif -    cbs <- dlsym dll "callback_system_step" -    let cbs' = mkCallbackSystemStepFunction cbs +    eds <- dlsym dll "entity_set" +    let eds' = mkEntitySetFunction eds+     edg <- dlsym dll "entity_get_data"     let edg' = mkEntityGetDataFunction edg      edr <- dlsym dll "entity_data_read"     let edr' = mkEntityDataReadFunction edr -    edd <- dlsym dll "entity_data_release"-    let edd' = mkEntityDataReleaseFunction edd+    edrl <- dlsym dll "entity_data_release"+    let edrl' = mkEntityDataReleaseFunction edrl -    ref <- newIORef $ EntityInterface efc' efs' cbc' cbr' cbs' edg' edr' edd'++    olc <- dlsym dll "object_lib_system_create" +    let olc' = mkObjectLibSystemCreateFunction olc++    ola <- dlsym dll "object_lib_system_add_entity" +    let ola' = mkObjectLibSystemAddEntityFunction ola++    ols <- dlsym dll "object_lib_system_step" +    let ols' = mkObjectLibSystemStepFunction ols+++    cbc <- dlsym dll "callback_system_create" +    let cbc' = mkCallbackSystemCreateFunction cbc++    cbr <- dlsym dll "callback_system_register_receiver" +    let cbr' = mkCallbackSystemRegisterReceiverFunction cbr++    cbs <- dlsym dll "callback_system_step" +    let cbs' = mkCallbackSystemStepFunction cbs+++    ref <- newIORef $ EntityInterface ec' ed' ei' eif'  eds' edg' edr' edrl'  olc' ola' ols'  cbc' cbr' cbs'      return ref   ) #endif@@ -209,24 +291,42 @@ unsafeUseAsCStringLen' str fn =    unsafeUseAsCStringLen str (\(ptr, len) -> fn (ptr, fromIntegral len)) ++ entityCreate :: (ByteString) -> IO ((Ptr ())) entityCreate a1 =   unsafeUseAsCStringLen' a1 $ \(a1'1, a1'2) ->    alloca $ \a2' ->    (do     dei <- readIORef dynamicEI-    (efCreate dei) a1'1  a1'2 a2') >>+    (eCreate dei) a1'1  a1'2 a2') >>   peek  a2' >>= \a2'' ->    return (a2'') +entityDestroy :: Ptr () -> IO ()+entityDestroy a1 =+  (do+    dei <- readIORef dynamicEI+    (eDestroy dei) a1) >>+  return () +entityId :: Ptr () -> IO ByteString+entityId ep = do+  dei <- readIORef dynamicEI+  p <- ((eId dei) ep)+  bs <- packCStringLen (p, 16)+  (eIdFree dei) p+  return bs+++ entitySet :: (ByteString) -> (Ptr ()) -> IO () entitySet a1 a2 =   unsafeUseAsCStringLen' a1 $ \(a1'1, a1'2) ->    let {a2' = id a2} in    (do     dei <- readIORef dynamicEI-    (efSet dei) a1'1  a1'2 a2') >>+    (edSet dei) a1'1  a1'2 a2') >>   return ()  entityGetData :: (Ptr ()) -> Word64 -> IO ((Ptr ()))@@ -258,12 +358,42 @@     (edRelease dei) a1     return () +++objectLibSystemCreate :: IO ((Ptr ()))+objectLibSystemCreate =+  alloca $ \a1' -> +  (do+    dei <- readIORef dynamicEI+    (olsCreate dei) a1') >>+  peek  a1'>>= \a1'' -> +  return (a1'')++objectLibSystemAddEntity :: (Ptr ()) -> (Ptr ()) -> IO ()+objectLibSystemAddEntity a1 a2 =+  let {a1' = id a1; a2' = id a2} in +  (do+    dei <- readIORef dynamicEI+    (olsAddEntity dei) a1' a2') >>+  return ()++objectLibSystemStep :: (Ptr ()) -> IO ()+objectLibSystemStep a1 =+  let {a1' = id a1} in +  (do+    dei <- readIORef dynamicEI+    (olsStep dei) a1') >>+  return ()++++ callbackSystemCreate :: IO ((Ptr ())) callbackSystemCreate =   alloca $ \a1' ->    (do     dei <- readIORef dynamicEI-    (cbsfCreate dei) a1') >>+    (cbsCreate dei) a1') >>   peek  a1'>>= \a1'' ->    return (a1'') @@ -275,7 +405,7 @@   let {a4' = id a4} in    (do     dei <- readIORef dynamicEI-    (cbsfRegisterReceiver dei) a1' a2' a3' a4') >>+    (cbsRegisterReceiver dei) a1' a2' a3' a4') >>   return ()  callbackSystemStep :: (Ptr ()) -> IO ()@@ -283,7 +413,7 @@   let {a1' = id a1} in    (do     dei <- readIORef dynamicEI-    (cbsfStep dei) a1') >>+    (cbsStep dei) a1') >>   return ()  
LICENSE view
@@ -3,10 +3,10 @@  (c) 2015-2016 Peter Althainz -Fresco is licensed under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License. You may obtain a copy of the License at+Fresco Haskell is licensed under the Apache License, Version 2.0 (the "License"); you may not use this software 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. -You can obtain the latest version of the source code under http://www.github.com/urs-of-the-backwoods/Fresco.+You can obtain the latest version of the source code under http://www.github.com/urs-of-the-backwoods/fresco-haskell.
fresco-binding.cabal view
@@ -10,7 +10,7 @@ --  Name:                fresco-binding-Version:             0.1.1+Version:             0.2.0 Synopsis:            Fresco binding for Haskell Description:          	Fresco is a framwork for multi-language programming. This is the Haskell binding.