Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Defold engine meta #1665

Merged
merged 5 commits into from
Nov 11, 2022
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
40 changes: 40 additions & 0 deletions meta/3rd/Defold/config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name = 'Defold'
files = {'game.project', '*%.script', '*%.gui_script'}
configs = {
{
key = 'Lua.runtime.version',
action = 'set',
value = 'Lua 5.1',
},
{
key = 'Lua.workspace.library',
action = 'set',
value = {".internal"},
},
{
key = 'Lua.workspace.ignoreDir',
action = 'set',
value = {".internal"},
},
{
key = 'Lua.diagnostics.globals',
action = 'set',
value = {
"on_input",
"on_message",
"init",
"update",
"final"
},
},
{
key = 'files.associations',
action = 'set',
value = {
["*.script"] = "lua",
["*.gui_script"] = "lua",
["*.render_script"] = "lua",
["*.editor_script"] = "lua"
}
},
}
83 changes: 83 additions & 0 deletions meta/3rd/Defold/library/base.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
------@meta
---
---
---@class vector3
---@field x number
---@field y number
---@field z number
---@operator sub(vector3): vector3
---@operator add(vector3): vector3

---@class vector4
---@field x number
---@field y number
---@field z number
---@field w number
---@operator sub(vector4): vector4
---@operator add(vector4): vector4

---@class quaternion
---@field x number
---@field y number
---@field z number
---@field w number

---@alias quat quaternion

---@class url string|hash
---@field socket string|hash
---@field path string|hash
---@field fragment string|hash

---@alias hash userdata
---@alias constant userdata
---@alias bool boolean
---@alias float number
---@alias object userdata
---@alias matrix4 userdata
---@alias node userdata

--mb use number instead of vector4
---@alias vector vector4

--luasocket
---@alias master userdata
---@alias unconnected userdata
---@alias client userdata

--render
---@alias constant_buffer userdata
---@alias render_target userdata
---@alias predicate userdata

--- Calls error if the value of its argument `v` is false (i.e., **nil** or
--- **false**); otherwise, returns all its arguments. In case of error,
--- `message` is the error object; when absent, it defaults to "assertion
--- failed!"
---@generic ANY
---@overload fun(v:any):any
---@param v ANY
---@param message string
---@return ANY
function assert(v,message) return v end

---@param self object
function init(self) end

---@param self object
---@param dt number
function update(self, dt) end

---@param self object
---@param message_id hash
---@param message table
---@param sender url
function on_message(self, message_id, message, sender) end

---@param self object
---@param action_id hash
---@param action table
function on_input(self, action_id, action) end

---@param self object
function final(self) end;
68 changes: 68 additions & 0 deletions meta/3rd/Defold/library/buffer.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---Buffer API documentation
---Functions for manipulating buffers and streams
---@class buffer
buffer = {}
---float32
buffer.VALUE_TYPE_FLOAT32 = nil
---int16
buffer.VALUE_TYPE_INT16 = nil
---int32
buffer.VALUE_TYPE_INT32 = nil
---int64
buffer.VALUE_TYPE_INT64 = nil
---int8
buffer.VALUE_TYPE_INT8 = nil
---uint16
buffer.VALUE_TYPE_UINT16 = nil
---uint32
buffer.VALUE_TYPE_UINT32 = nil
---uint64
buffer.VALUE_TYPE_UINT64 = nil
---uint8
buffer.VALUE_TYPE_UINT8 = nil
---Copy all data streams from one buffer to another, element wise.
--- Each of the source streams must have a matching stream in the
---destination buffer. The streams must match in both type and size.
---The source and destination buffer can be the same.
---@param dst buffer # the destination buffer
---@param dstoffset number # the offset to start copying data to
---@param src buffer # the source data buffer
---@param srcoffset number # the offset to start copying data from
---@param count number # the number of elements to copy
function buffer.copy_buffer(dst, dstoffset, src, srcoffset, count) end

---Copy a specified amount of data from one stream to another.
--- The value type and size must match between source and destination streams.
---The source and destination streams can be the same.
---@param dst bufferstream # the destination stream
---@param dstoffset number # the offset to start copying data to (measured in value type)
---@param src bufferstream # the source data stream
---@param srcoffset number # the offset to start copying data from (measured in value type)
---@param count number # the number of values to copy (measured in value type)
function buffer.copy_stream(dst, dstoffset, src, srcoffset, count) end

---Create a new data buffer containing a specified set of streams. A data buffer
---can contain one or more streams with typed data. This is useful for managing
---compound data, for instance a vertex buffer could contain separate streams for
---vertex position, color, normal etc.
---@param element_count number # The number of elements the buffer should hold
---@param declaration table # A table where each entry (table) describes a stream
---@return buffer # the new buffer
function buffer.create(element_count, declaration) end

---Get a copy of all the bytes from a specified stream as a Lua string.
---@param buffer buffer # the source buffer
---@param stream_name hash # the name of the stream
---@return string # the buffer data as a Lua string
function buffer.get_bytes(buffer, stream_name) end

---Get a specified stream from a buffer.
---@param buffer buffer # the buffer to get the stream from
---@param stream_name hash|string # the stream name
---@return bufferstream # the data stream
function buffer.get_stream(buffer, stream_name) end




return buffer
24 changes: 24 additions & 0 deletions meta/3rd/Defold/library/built-ins.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---Built-ins API documentation
---Built-in scripting functions.

---All ids in the engine are represented as hashes, so a string needs to be hashed
---before it can be compared with an id.
---@param s string # string to hash
---@return hash # a hashed string
function hash(s) end

---Returns a hexadecimal representation of a hash value.
---The returned string is always padded with leading zeros.
---@param h hash # hash value to get hex string for
---@return string # hex representation of the hash
function hash_to_hex(h) end

---Pretty printing of Lua values. This function prints Lua values
---in a manner similar to +print()+, but will also recurse into tables
---and pretty print them. There is a limit to how deep the function
---will recurse.
---@param v any # value to print
function pprint(v) end



54 changes: 54 additions & 0 deletions meta/3rd/Defold/library/collection_factory.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---Collection factory API documentation
---Functions for controlling collection factory components which are
---used to dynamically spawn collections into the runtime.
---@class collectionfactory
collectionfactory = {}
---loaded
collectionfactory.STATUS_LOADED = nil
---loading
collectionfactory.STATUS_LOADING = nil
---unloaded
collectionfactory.STATUS_UNLOADED = nil
---The URL identifies the collectionfactory component that should do the spawning.
---Spawning is instant, but spawned game objects get their first update calls the following frame. The supplied parameters for position, rotation and scale
---will be applied to the whole collection when spawned.
---Script properties in the created game objects can be overridden through
---a properties-parameter table. The table should contain game object ids
---(hash) as keys and property tables as values to be used when initiating each
---spawned game object.
---See go.property for more information on script properties.
---The function returns a table that contains a key for each game object
---id (hash), as addressed if the collection file was top level, and the
---corresponding spawned instance id (hash) as value with a unique path
---prefix added to each instance.
--- Calling collectionfactory.create <> create on a collection factory that is marked as dynamic without having loaded resources
---using collectionfactory.load <> will synchronously load and create resources which may affect application performance.
---@param url string|hash|url # the collection factory component to be used
---@param position vector3? # position to assign to the newly spawned collection
---@param rotation quaternion? # rotation to assign to the newly spawned collection
---@param properties table? # table of script properties to propagate to any new game object instances
---@param scale number? # uniform scaling to apply to the newly spawned collection (must be greater than 0).
---@return table # a table mapping the id:s from the collection to the new instance id:s
function collectionfactory.create(url, position, rotation, properties, scale) end

---This returns status of the collection factory.
---Calling this function when the factory is not marked as dynamic loading always returns COMP_COLLECTION_FACTORY_STATUS_LOADED.
---@param url string|hash|url? # the collection factory component to get status from
---@return constant # status of the collection factory component
function collectionfactory.get_status(url) end

---Resources loaded are referenced by the collection factory component until the existing (parent) collection is destroyed or collectionfactory.unload is called.
---Calling this function when the factory is not marked as dynamic loading does nothing.
---@param url string|hash|url? # the collection factory component to load
---@param complete_function (fun(self: object, url: url, result: boolean))? # function to call when resources are loaded.
function collectionfactory.load(url, complete_function) end

---This decreases the reference count for each resource loaded with collectionfactory.load. If reference is zero, the resource is destroyed.
---Calling this function when the factory is not marked as dynamic loading does nothing.
---@param url string|hash|url? # the collection factory component to unload
function collectionfactory.unload(url) end




return collectionfactory
9 changes: 9 additions & 0 deletions meta/3rd/Defold/library/collection_proxy.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---Collection proxy API documentation
---Messages for controlling and interacting with collection proxies
---which are used to dynamically load collections into the runtime.
---@class collectionproxy
collectionproxy = {}



return collectionproxy
Loading