Input in script proof of concept working

master
Joey Pollack 3 years ago
parent 3c55ca9c5b
commit df9eb0a4f7

@ -39,6 +39,8 @@ namespace lunarium
OpRes CoreAPI::Initialize(WrenState& sman)
{
mCat = sman.GetLogCat();
// Initialize Foreign methods
mForeignMethods.push_back({"CoreAPI", "Core", true, "IsKeyDown(_)", (ForeignMethod)&CoreAPI::IsKeyDown});
// Register callbacks
sman.RegisterForeignMethodBinder((FMBinder*)&CoreAPI::ForeignMethodBinder);
@ -55,8 +57,9 @@ namespace lunarium
mScript.SetModuleName("CoreAPI");
std::string code = File::ReadTextFile("core_api.wren"); // This will eventually move to internal data
mScript.SetScriptCode(code);
sman.RunScript(&mScript);
// Register methods
// Get Method Handles
// return OpRes::Fail("CoreAPI::Initialize not implemented yet!");
return OpRes::OK();
@ -70,7 +73,7 @@ namespace lunarium
{
if (FMID == (*iter))
{
iter->FM;
return iter->FM;
}
}
@ -118,8 +121,10 @@ namespace lunarium
}
}
bool CoreAPI::IsKeyDown(WrenVM* vm)
void CoreAPI::IsKeyDown(WrenVM* vm)
{
return false;
u32 key_code = (u32)wrenGetSlotDouble(vm, 1);
bool result = Core::Input().IsKeyDown((KeyCode)key_code, true);
wrenSetSlotBool(vm, 0, result);
}
}

@ -65,7 +65,7 @@ namespace lunarium
static void SetWindowSize(int w, int h);
static void Log(int level, const char* msg);
static bool IsKeyDown(WrenVM* vm);
static void IsKeyDown(WrenVM* vm);
};
}

@ -6,6 +6,8 @@
* Description - The Core API exposes core Lunarium features to scripts
******************************************************************************/
import "KeyCodes" for KeyCodes
class Core {
//foreign static IsKeyDown(key)
foreign static IsKeyDown(key)
}

@ -35,6 +35,7 @@ namespace lunarium
wrenInitConfiguration(&config);
config.writeFn = WrenState::WriteFN;
config.errorFn = WrenState::ErrorFN;
config.bindForeignMethodFn = WrenState::BindForeignMethodFN;
mpVM = wrenNewVM(&config);

Loading…
Cancel
Save