Initialized Extension
This commit is contained in:
parent
95079f9bff
commit
0746a2a88e
10
.gitignore
vendored
Normal file
10
.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
/.internal
|
||||||
|
/build
|
||||||
|
.externalToolBuilders
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
.lock-wscript
|
||||||
|
*.pyc
|
||||||
|
.project
|
||||||
|
.cproject
|
||||||
|
builtins
|
21
LICENSE.md
Normal file
21
LICENSE.md
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2019 Defold
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
2
SIGW/ext.manifest
Normal file
2
SIGW/ext.manifest
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# C++ symbol in your extension
|
||||||
|
name: "MyExtension"
|
112
SIGW/src/myextension.cpp
Normal file
112
SIGW/src/myextension.cpp
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
// myextension.cpp
|
||||||
|
// Extension lib defines
|
||||||
|
#define LIB_NAME "MyExtension"
|
||||||
|
#define MODULE_NAME "myextension"
|
||||||
|
|
||||||
|
// include the Defold SDK
|
||||||
|
#include <dmsdk/sdk.h>
|
||||||
|
|
||||||
|
static int Reverse(lua_State* L)
|
||||||
|
{
|
||||||
|
// The number of expected items to be on the Lua stack
|
||||||
|
// once this struct goes out of scope
|
||||||
|
DM_LUA_STACK_CHECK(L, 1);
|
||||||
|
|
||||||
|
// Check and get parameter string from stack
|
||||||
|
char* str = (char*)luaL_checkstring(L, 1);
|
||||||
|
|
||||||
|
// Reverse the string
|
||||||
|
int len = strlen(str);
|
||||||
|
for(int i = 0; i < len / 2; i++) {
|
||||||
|
const char a = str[i];
|
||||||
|
const char b = str[len - i - 1];
|
||||||
|
str[i] = b;
|
||||||
|
str[len - i - 1] = a;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Put the reverse string on the stack
|
||||||
|
lua_pushstring(L, str);
|
||||||
|
|
||||||
|
// Return 1 item
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Functions exposed to Lua
|
||||||
|
static const luaL_reg Module_methods[] =
|
||||||
|
{
|
||||||
|
{"reverse", Reverse},
|
||||||
|
{0, 0}
|
||||||
|
};
|
||||||
|
|
||||||
|
static void LuaInit(lua_State* L)
|
||||||
|
{
|
||||||
|
int top = lua_gettop(L);
|
||||||
|
|
||||||
|
// Register lua names
|
||||||
|
luaL_register(L, MODULE_NAME, Module_methods);
|
||||||
|
|
||||||
|
lua_pop(L, 1);
|
||||||
|
assert(top == lua_gettop(L));
|
||||||
|
}
|
||||||
|
|
||||||
|
dmExtension::Result AppInitializeMyExtension(dmExtension::AppParams* params)
|
||||||
|
{
|
||||||
|
dmLogInfo("AppInitializeMyExtension\n");
|
||||||
|
return dmExtension::RESULT_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
dmExtension::Result InitializeMyExtension(dmExtension::Params* params)
|
||||||
|
{
|
||||||
|
// Init Lua
|
||||||
|
LuaInit(params->m_L);
|
||||||
|
dmLogInfo("Registered %s Extension\n", MODULE_NAME);
|
||||||
|
return dmExtension::RESULT_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
dmExtension::Result AppFinalizeMyExtension(dmExtension::AppParams* params)
|
||||||
|
{
|
||||||
|
dmLogInfo("AppFinalizeMyExtension\n");
|
||||||
|
return dmExtension::RESULT_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
dmExtension::Result FinalizeMyExtension(dmExtension::Params* params)
|
||||||
|
{
|
||||||
|
dmLogInfo("FinalizeMyExtension\n");
|
||||||
|
return dmExtension::RESULT_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
dmExtension::Result OnUpdateMyExtension(dmExtension::Params* params)
|
||||||
|
{
|
||||||
|
dmLogInfo("OnUpdateMyExtension\n");
|
||||||
|
return dmExtension::RESULT_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnEventMyExtension(dmExtension::Params* params, const dmExtension::Event* event)
|
||||||
|
{
|
||||||
|
switch(event->m_Event)
|
||||||
|
{
|
||||||
|
case dmExtension::EVENT_ID_ACTIVATEAPP:
|
||||||
|
dmLogInfo("OnEventMyExtension - EVENT_ID_ACTIVATEAPP\n");
|
||||||
|
break;
|
||||||
|
case dmExtension::EVENT_ID_DEACTIVATEAPP:
|
||||||
|
dmLogInfo("OnEventMyExtension - EVENT_ID_DEACTIVATEAPP\n");
|
||||||
|
break;
|
||||||
|
case dmExtension::EVENT_ID_ICONIFYAPP:
|
||||||
|
dmLogInfo("OnEventMyExtension - EVENT_ID_ICONIFYAPP\n");
|
||||||
|
break;
|
||||||
|
case dmExtension::EVENT_ID_DEICONIFYAPP:
|
||||||
|
dmLogInfo("OnEventMyExtension - EVENT_ID_DEICONIFYAPP\n");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
dmLogWarning("OnEventMyExtension - Unknown event id\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Defold SDK uses a macro for setting up extension entry points:
|
||||||
|
//
|
||||||
|
// DM_DECLARE_EXTENSION(symbol, name, app_init, app_final, init, update, on_event, final)
|
||||||
|
|
||||||
|
// MyExtension is the C++ symbol that holds all relevant extension data.
|
||||||
|
// It must match the name field in the `ext.manifest`
|
||||||
|
DM_DECLARE_EXTENSION(MyExtension, LIB_NAME, AppInitializeMyExtension, AppFinalizeMyExtension, InitializeMyExtension, OnUpdateMyExtension, OnEventMyExtension, FinalizeMyExtension)
|
37
example/example.collection
Normal file
37
example/example.collection
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
name: "main"
|
||||||
|
scale_along_z: 0
|
||||||
|
embedded_instances {
|
||||||
|
id: "go"
|
||||||
|
data: "components {\n"
|
||||||
|
" id: \"example\"\n"
|
||||||
|
" component: \"/example/example.script\"\n"
|
||||||
|
" position {\n"
|
||||||
|
" x: 0.0\n"
|
||||||
|
" y: 0.0\n"
|
||||||
|
" z: 0.0\n"
|
||||||
|
" }\n"
|
||||||
|
" rotation {\n"
|
||||||
|
" x: 0.0\n"
|
||||||
|
" y: 0.0\n"
|
||||||
|
" z: 0.0\n"
|
||||||
|
" w: 1.0\n"
|
||||||
|
" }\n"
|
||||||
|
"}\n"
|
||||||
|
""
|
||||||
|
position {
|
||||||
|
x: 0.0
|
||||||
|
y: 0.0
|
||||||
|
z: 0.0
|
||||||
|
}
|
||||||
|
rotation {
|
||||||
|
x: 0.0
|
||||||
|
y: 0.0
|
||||||
|
z: 0.0
|
||||||
|
w: 1.0
|
||||||
|
}
|
||||||
|
scale3 {
|
||||||
|
x: 1.0
|
||||||
|
y: 1.0
|
||||||
|
z: 1.0
|
||||||
|
}
|
||||||
|
}
|
30
example/example.script
Normal file
30
example/example.script
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
function init(self)
|
||||||
|
local s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
|
local reverse_s = myextension.reverse(s)
|
||||||
|
print(reverse_s) --> ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba
|
||||||
|
end
|
||||||
|
|
||||||
|
function final(self)
|
||||||
|
-- Add finalization code here
|
||||||
|
-- Remove this function if not needed
|
||||||
|
end
|
||||||
|
|
||||||
|
function update(self, dt)
|
||||||
|
-- Add update code here
|
||||||
|
-- Remove this function if not needed
|
||||||
|
end
|
||||||
|
|
||||||
|
function on_message(self, message_id, message, sender)
|
||||||
|
-- Add message-handling code here
|
||||||
|
-- Remove this function if not needed
|
||||||
|
end
|
||||||
|
|
||||||
|
function on_input(self, action_id, action)
|
||||||
|
-- Add input-handling code here
|
||||||
|
-- Remove this function if not needed
|
||||||
|
end
|
||||||
|
|
||||||
|
function on_reload(self)
|
||||||
|
-- Add reload-handling code here
|
||||||
|
-- Remove this function if not needed
|
||||||
|
end
|
16
game.project
Normal file
16
game.project
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
[bootstrap]
|
||||||
|
main_collection = /example/example.collectionc
|
||||||
|
|
||||||
|
[script]
|
||||||
|
shared_state = 1
|
||||||
|
|
||||||
|
[display]
|
||||||
|
width = 960
|
||||||
|
height = 640
|
||||||
|
|
||||||
|
[project]
|
||||||
|
title = SIGW-Extension
|
||||||
|
|
||||||
|
[library]
|
||||||
|
include_dirs = SIGW
|
||||||
|
|
4
input/game.input_binding
Normal file
4
input/game.input_binding
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
mouse_trigger {
|
||||||
|
input: MOUSE_BUTTON_1
|
||||||
|
action: "touch"
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user