You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
---Lua BitOp is free software, released under the MIT license (same license as the Lua core).
6
-
---
7
5
---Lua BitOp is compatible with the built-in bitwise operations in LuaJIT 2.0 and is used
8
6
---on platforms where Defold runs without LuaJIT.
9
-
---
10
7
---For clarity the examples assume the definition of a helper function printx().
11
8
---This prints its argument as an unsigned 32 bit hexadecimal number on all platforms:
12
9
---function printx(x)
@@ -22,59 +19,70 @@ bit = {}
22
19
---@paramnnumber number of bits
23
20
---@returnnumber bitwise arithmetic right-shifted number
24
21
functionbit.arshift(x, n) end
22
+
25
23
---Returns the bitwise and of all of its arguments. Note that more than two arguments are allowed.
26
24
---@paramx1number number
27
-
---@param ... numbernumber(s)
25
+
--- ... number number(s)
28
26
---@returnnumber bitwise and of the provided arguments
29
27
functionbit.band(x1, ...) end
28
+
30
29
---Returns the bitwise not of its argument.
31
30
---@paramxnumber number
32
31
---@returnnumber bitwise not of number x
33
32
functionbit.bnot(x) end
33
+
34
34
---Returns the bitwise or of all of its arguments. Note that more than two arguments are allowed.
35
35
---@paramx1number number
36
-
---@param ... numbernumber(s)
36
+
--- ... number number(s)
37
37
---@returnnumber bitwise or of the provided arguments
38
38
functionbit.bor(x1, ...) end
39
+
39
40
---Swaps the bytes of its argument and returns it. This can be used to convert little-endian 32 bit numbers to big-endian 32 bit numbers or vice versa.
40
41
---@paramxnumber number
41
42
---@returnnumber bitwise swapped number
42
43
functionbit.bswap(x) end
44
+
43
45
---Returns the bitwise xor of all of its arguments. Note that more than two arguments are allowed.
44
46
---@paramx1number number
45
-
---@param ... numbernumber(s)
47
+
--- ... number number(s)
46
48
---@returnnumber bitwise xor of the provided arguments
47
49
functionbit.bxor(x1, ...) end
50
+
48
51
---Returns the bitwise logical left-shift of its first argument by the number of bits given by the second argument.
49
52
---Logical shifts treat the first argument as an unsigned number and shift in 0-bits.
50
53
---Only the lower 5 bits of the shift count are used (reduces to the range [0..31]).
51
54
---@paramxnumber number
52
55
---@paramnnumber number of bits
53
56
---@returnnumber bitwise logical left-shifted number
54
57
functionbit.lshift(x, n) end
58
+
55
59
---Returns the bitwise left rotation of its first argument by the number of bits given by the second argument. Bits shifted out on one side are shifted back in on the other side.
56
60
---Only the lower 5 bits of the rotate count are used (reduces to the range [0..31]).
57
61
---@paramxnumber number
58
62
---@paramnnumber number of bits
59
63
---@returnnumber bitwise left-rotated number
60
64
functionbit.rol(x, n) end
65
+
61
66
---Returns the bitwise right rotation of its first argument by the number of bits given by the second argument. Bits shifted out on one side are shifted back in on the other side.
62
67
---Only the lower 5 bits of the rotate count are used (reduces to the range [0..31]).
63
68
---@paramxnumber number
64
69
---@paramnnumber number of bits
65
70
---@returnnumber bitwise right-rotated number
66
71
functionbit.ror(x, n) end
72
+
67
73
---Returns the bitwise logical right-shift of its first argument by the number of bits given by the second argument.
68
74
---Logical shifts treat the first argument as an unsigned number and shift in 0-bits.
69
75
---Only the lower 5 bits of the shift count are used (reduces to the range [0..31]).
70
76
---@paramxnumber number
71
77
---@paramnnumber number of bits
72
78
---@returnnumber bitwise logical right-shifted number
73
79
functionbit.rshift(x, n) end
80
+
74
81
---Normalizes a number to the numeric range for bit operations and returns it. This function is usually not needed since all bit operations already normalize all of their input arguments.
75
82
---@paramxnumber number to normalize
76
83
---@returnnumber normalized number
77
84
functionbit.tobit(x) end
85
+
78
86
---Converts its first argument to a hex string. The number of hex digits is given by the absolute value of the optional second argument. Positive numbers between 1 and 8 generate lowercase hex digits. Negative numbers generate uppercase hex digits. Only the least-significant 4*|n| bits are used. The default is to generate 8 lowercase hex digits.
---The URL identifies the collectionfactory component that should do the spawning.
13
-
---
14
13
---Spawning is instant, but spawned game objects get their first update calls the following frame. The supplied parameters for position, rotation and scale
15
14
---will be applied to the whole collection when spawned.
16
-
---
17
15
---Script properties in the created game objects can be overridden through
18
16
---a properties-parameter table. The table should contain game object ids
19
17
---(hash) as keys and property tables as values to be used when initiating each
20
18
---spawned game object.
21
-
---
22
19
---See go.property for more information on script properties.
23
-
---
24
20
---The function returns a table that contains a key for each game object
25
21
---id (hash), as addressed if the collection file was top level, and the
26
22
---corresponding spawned instance id (hash) as value with a unique path
27
23
---prefix added to each instance.
28
-
---
29
24
--- Calling collectionfactory.create <> create on a collection factory that is marked as dynamic without having loaded resources
30
25
---using collectionfactory.load <> will synchronously load and create resources which may affect application performance.
31
-
---@paramurlstring| hash| url the collection factory component to be used
26
+
---@paramurlstring|hash|url the collection factory component to be used
32
27
---@parampositionvector3 position to assign to the newly spawned collection
33
28
---@paramrotationquaternion rotation to assign to the newly spawned collection
34
29
---@parampropertiestable table of script properties to propagate to any new game object instances
35
30
---@paramscalenumber uniform scaling to apply to the newly spawned collection (must be greater than 0).
36
31
---@returntable a table mapping the id:s from the collection to the new instance id:s
37
32
functioncollectionfactory.create(url, position, rotation, properties, scale) end
33
+
38
34
---This returns status of the collection factory.
39
-
---
40
35
---Calling this function when the factory is not marked as dynamic loading always returns COMP_COLLECTION_FACTORY_STATUS_LOADED.
41
-
---@paramurlstring| hash| url the collection factory component to get status from
36
+
---@paramurlstring|hash|url the collection factory component to get status from
42
37
---@returnconstant status of the collection factory component
43
38
functioncollectionfactory.get_status(url) end
39
+
44
40
---Resources loaded are referenced by the collection factory component until the existing (parent) collection is destroyed or collectionfactory.unload is called.
45
-
---
46
41
---Calling this function when the factory is not marked as dynamic loading does nothing.
47
-
---@paramurlstring| hash| url the collection factory component to load
42
+
---@paramurlstring|hash|url the collection factory component to load
48
43
---@paramcomplete_functionfunction(self, url, result)) function to call when resources are loaded.
49
44
functioncollectionfactory.load(url, complete_function) end
45
+
50
46
---This decreases the reference count for each resource loaded with collectionfactory.load. If reference is zero, the resource is destroyed.
51
-
---
52
47
---Calling this function when the factory is not marked as dynamic loading does nothing.
53
-
---@paramurlstring| hash| url the collection factory component to unload
48
+
---@paramurlstring|hash|url the collection factory component to unload
---Create a physics joint between two collision object components.
16
-
---
17
16
---Note: Currently only supported in 2D physics.
18
17
---@paramjoint_typenumber the joint type
19
-
---@paramcollisionobject_astring| hash| url first collision object
20
-
---@paramjoint_idstring| hash id of the joint
18
+
---@paramcollisionobject_astring|hash|url first collision object
19
+
---@paramjoint_idstring|hash id of the joint
21
20
---@paramposition_avector3 local position where to attach the joint on the first collision object
22
-
---@paramcollisionobject_bstring| hash| url second collision object
21
+
---@paramcollisionobject_bstring|hash|url second collision object
23
22
---@paramposition_bvector3 local position where to attach the joint on the second collision object
24
-
---@parampropertiestable optional joint specific properties table
23
+
---@parampropertiestable optional joint specific properties table See each joint type for possible properties field. The one field that is accepted for all joint types is: - boolean collide_connected: Set this flag to true if the attached bodies should collide.
25
24
functionphysics.create_joint(joint_type, collisionobject_a, joint_id, position_a, collisionobject_b, position_b, properties) end
25
+
26
26
---Destroy an already physics joint. The joint has to be created before a
27
27
---destroy can be issued.
28
-
---
29
28
---Note: Currently only supported in 2D physics.
30
-
---@paramcollisionobjectstring| hash| url collision object where the joint exist
31
-
---@paramjoint_idstring| hash id of the joint
29
+
---@paramcollisionobjectstring|hash|url collision object where the joint exist
30
+
---@paramjoint_idstring|hash id of the joint
32
31
functionphysics.destroy_joint(collisionobject, joint_id) end
32
+
33
33
---Get the gravity in runtime. The gravity returned is not global, it will return
34
34
---the gravity for the collection that the function is called from.
35
-
---
36
35
---Note: For 2D physics the z component will always be zero.
37
-
---@return[type:vector3] gravity vector of collection
36
+
---@returnvector3 gravity vector of collection
38
37
functionphysics.get_gravity() end
38
+
39
39
---Get a table for properties for a connected joint. The joint has to be created before
40
40
---properties can be retrieved.
41
-
---
42
41
---Note: Currently only supported in 2D physics.
43
-
---@paramcollisionobjectstring| hash| url collision object where the joint exist
44
-
---@paramjoint_idstring| hash id of the joint
45
-
---@returnboolean
42
+
---@paramcollisionobjectstring|hash|url collision object where the joint exist
43
+
---@paramjoint_idstring|hash id of the joint
44
+
---@returntable properties table. See the joint types for what fields are available, the only field available for all types is:
46
45
functionphysics.get_joint_properties(collisionobject, joint_id) end
46
+
47
47
---Get the reaction force for a joint. The joint has to be created before
48
48
---the reaction force can be calculated.
49
-
---
50
49
---Note: Currently only supported in 2D physics.
51
-
---@paramcollisionobjectstring| hash| url collision object where the joint exist
52
-
---@paramjoint_idstring| hash id of the joint
50
+
---@paramcollisionobjectstring|hash|url collision object where the joint exist
51
+
---@paramjoint_idstring|hash id of the joint
53
52
---@returnvector3 reaction force for the joint
54
53
functionphysics.get_joint_reaction_force(collisionobject, joint_id) end
54
+
55
55
---Get the reaction torque for a joint. The joint has to be created before
56
56
---the reaction torque can be calculated.
57
-
---
58
57
---Note: Currently only supported in 2D physics.
59
-
---@paramcollisionobjectstring| hash| url collision object where the joint exist
60
-
---@paramjoint_idstring| hash id of the joint
58
+
---@paramcollisionobjectstring|hash|url collision object where the joint exist
59
+
---@paramjoint_idstring|hash id of the joint
61
60
---@returnfloat the reaction torque on bodyB in N*m.
62
61
functionphysics.get_joint_reaction_torque(collisionobject, joint_id) end
62
+
63
63
---Ray casts are used to test for intersections against collision objects in the physics world.
64
64
---Collision objects of types kinematic, dynamic and static are tested against. Trigger objects
65
65
---do not intersect with ray casts.
@@ -68,8 +68,10 @@ function physics.get_joint_reaction_torque(collisionobject, joint_id) end
68
68
---@paramfromvector3 the world position of the start of the ray
69
69
---@paramtovector3 the world position of the end of the ray
70
70
---@paramgroupstable a lua table containing the hashed groups for which to test collisions against
71
-
---@returntable It returns a table. If missed it returns nil. See
72
-
functionphysics.raycast(from, to, groups) end
71
+
---@paramoptionstable a lua table containing options for the raycast.
72
+
---@returntable It returns a list. If missed it returns nil. See ray_cast_response for details on the returned values.
73
+
functionphysics.raycast(from, to, groups, options) end
74
+
73
75
---Ray casts are used to test for intersections against collision objects in the physics world.
74
76
---Collision objects of types kinematic, dynamic and static are tested against. Trigger objects
75
77
---do not intersect with ray casts.
@@ -81,35 +83,37 @@ function physics.raycast(from, to, groups) end
81
83
--- * If an object is hit, the result will be reported via a ray_cast_response message.
82
84
---
83
85
--- * If there is no object hit, the result will be reported via a ray_cast_missed message.
84
-
85
86
---@paramfromvector3 the world position of the start of the ray
86
87
---@paramtovector3 the world position of the end of the ray
87
88
---@paramgroupstable a lua table containing the hashed groups for which to test collisions against
88
-
---@paramrequest_idnumber a number between [0,-255]. It will be sent back in the response for identification, 0 by default
89
+
---@paramrequest_idnumber] a number between [0,-255. It will be sent back in the response for identification, 0 by default
89
90
functionphysics.raycast_async(from, to, groups, request_id) end
91
+
90
92
---Set the gravity in runtime. The gravity change is not global, it will only affect
91
93
---the collection that the function is called from.
92
-
---
93
94
---Note: For 2D physics the z component of the gravity vector will be ignored.
94
95
---@paramgravityvector3 the new gravity vector
95
96
functionphysics.set_gravity(gravity) end
97
+
96
98
---Flips the collision shapes horizontally for a collision object
97
-
---@paramurlstring| hash| url the collision object that should flip its shapes
98
-
---@paramflipboolean
99
+
---@paramurlstring|hash|url the collision object that should flip its shapes
100
+
---@paramflipboolean true if the collision object should flip its shapes, false if not
99
101
functionphysics.set_hflip(url, flip) end
102
+
100
103
---Updates the properties for an already connected joint. The joint has to be created before
101
104
---properties can be changed.
102
-
---
103
105
---Note: Currently only supported in 2D physics.
104
-
---@paramcollisionobjectstring| hash| url collision object where the joint exist
105
-
---@paramjoint_idstring| hash id of the joint
106
-
---@parampropertiestable joint specific properties table
106
+
---@paramcollisionobjectstring|hash|url collision object where the joint exist
107
+
---@paramjoint_idstring|hash id of the joint
108
+
---@parampropertiestable joint specific properties table Note: The collide_connected field cannot be updated/changed after a connection has been made.
107
109
functionphysics.set_joint_properties(collisionobject, joint_id, properties) end
110
+
108
111
---Flips the collision shapes vertically for a collision object
109
-
---@paramurlstring| hash| url the collision object that should flip its shapes
110
-
---@paramflipboolean
112
+
---@paramurlstring|hash|url the collision object that should flip its shapes
113
+
---@paramflipboolean true if the collision object should flip its shapes, false if not
0 commit comments