3838#include < projectloader_hooks.h>
3939#include < compiler.h>
4040#include < compilerfactory.h>
41- #include < sqplus.h>
42- #include < sc_base_types.h>
41+ #include < sc_utils.h>
42+ #include < sc_typeinfo_all.h>
43+ #include < scriptingmanager.h>
4344#include < logmanager.h>
4445
4546#include " resultmap.h"
@@ -55,11 +56,6 @@ namespace
5556 // Register the plugin
5657 PluginRegistrant<lib_finder> reg (_T(" lib_finder" ));
5758
58- // Some class required for scripting
59- class LibFinder
60- {
61- };
62-
6359 static const bool ExtraEventPresent = true ;
6460};
6561
@@ -384,27 +380,105 @@ bool lib_finder::TryAddLibrary(CompileTargetBase* Target,LibraryResult* Result)
384380 return true ;
385381}
386382
383+ namespace ScriptBindings
384+ {
385+
386+ // Dummy type
387+ struct LibFinder {};
388+
389+ template <>
390+ struct TypeInfo <LibFinder> {
391+ static uint32_t typetag;
392+ static constexpr const SQChar *className = _SC(" LibFinder" );
393+ using baseClass = void ;
394+ };
395+
396+ uint32_t TypeInfo<LibFinder>::typetag = uint32_t (TypeTag::Unassigned);
397+
398+ template <bool (*func)(const wxString &, cbProject *, const wxString &)>
399+ SQInteger LibFinder_LibraryToProject (HSQUIRRELVM v)
400+ {
401+ // env table, LibName, Project, TargetName
402+ ExtractParams4<SkipParam, const wxString *, cbProject *, const wxString *> extractor (v);
403+ if (!extractor.Process (" LibFinder::LibraryToProject" ))
404+ return extractor.ErrorMessage ();
405+ const bool result = func (*extractor.p1 , extractor.p2 , *extractor.p3 );
406+ sq_pushbool (v, result);
407+ return 1 ;
408+ }
409+
410+ SQInteger LibFinder_SetupTargetManually (HSQUIRRELVM v)
411+ {
412+ // env table, Target
413+ ExtractParams2<SkipParam, CompileTargetBase *> extractor (v);
414+ if (!extractor.Process (" LibFinder::SetupTargetManually" ))
415+ return extractor.ErrorMessage ();
416+ const bool result = lib_finder::SetupTargetManually (extractor.p1 );
417+ sq_pushbool (v, result);
418+ return 1 ;
419+ }
420+
421+ SQInteger LibFinder_EnsureIsDefined (HSQUIRRELVM v)
422+ {
423+ // env table, ShortCode
424+ ExtractParams2<SkipParam, const wxString *> extractor (v);
425+ if (!extractor.Process (" LibFinder::EnsureIsDefined" ))
426+ return extractor.ErrorMessage ();
427+ const bool result = lib_finder::EnsureIsDefined (*extractor.p1 );
428+ sq_pushbool (v, result);
429+ return 1 ;
430+ }
431+
432+ } // namespace ScriptBindings
433+
387434void lib_finder::RegisterScripting ()
388435{
389- SqPlus::SQClassDef<LibFinder>(" LibFinder" )
390- .staticFunc (&lib_finder::AddLibraryToProject," AddLibraryToProject" )
391- .staticFunc (&lib_finder::IsLibraryInProject," IsLibraryInProject" )
392- .staticFunc (&lib_finder::RemoveLibraryFromProject," RemoveLibraryFromProject" )
393- .staticFunc (&lib_finder::SetupTargetManually," SetupTarget" )
394- .staticFunc (&lib_finder::EnsureIsDefined," EnsureLibraryDefined" )
395- ;
436+ ScriptingManager *scriptMgr = Manager::Get ()->GetScriptingManager ();
437+ HSQUIRRELVM v = scriptMgr->GetVM ();
438+ if (v)
439+ {
440+ using namespace ScriptBindings ;
441+
442+ TypeInfo<LibFinder>::typetag = scriptMgr->RequestClassTypeTag ();
443+
444+ PreserveTop preserveTop (v);
445+
446+ sq_pushroottable (v);
447+ const SQInteger classDecl = CreateClassDecl<LibFinder>(v, _SC (" LibFinder" ));
448+ BindStaticMethod (v, _SC (" AddLibraryToProject" ),
449+ LibFinder_LibraryToProject<lib_finder::AddLibraryToProject>,
450+ _SC (" LibFinder::AddLibraryToProject" ));
451+ BindStaticMethod (v, _SC (" IsLibraryInProject" ),
452+ LibFinder_LibraryToProject<lib_finder::IsLibraryInProject>,
453+ _SC (" LibFinder::IsLibraryInProject" ));
454+ BindStaticMethod (v, _SC (" RemoveLibraryFromProject" ),
455+ LibFinder_LibraryToProject<lib_finder::RemoveLibraryFromProject>,
456+ _SC (" LibFinder::RemoveLibraryFromProject" ));
457+ BindStaticMethod (v, _SC (" SetupTargetManually" ), LibFinder_SetupTargetManually,
458+ _SC (" LibFinder::SetupTargetManually" ));
459+ BindStaticMethod (v, _SC (" EnsureIsDefined" ), LibFinder_EnsureIsDefined,
460+ _SC (" LibFinder::EnsureIsDefined" ));
461+
462+ // Put the class in the root table. This must be last!
463+ sq_newslot (v, classDecl, SQFalse);
464+
465+ sq_poptop (v); // Pop root table.
466+ }
396467}
397468
398469void lib_finder::UnregisterScripting ()
399470{
400- Manager::Get ()->GetScriptingManager ();
401- HSQUIRRELVM v = SquirrelVM::GetVMPtr ();
402- if ( v )
471+ HSQUIRRELVM v = Manager::Get ()->GetScriptingManager ()->GetVM ();
472+ if (v)
403473 {
474+ using namespace ScriptBindings ;
475+ PreserveTop preserveTop (v);
404476 sq_pushroottable (v);
405- sq_pushstring (v," LibFinder" , -1 );
406- sq_deleteslot (v,-2 ,false );
477+ sq_pushstring (v, _SC ( " LibFinder" ), -1 );
478+ sq_deleteslot (v, -2 , false );
407479 sq_poptop (v);
480+
481+ TypeInfo<LibFinder>::typetag = uint32_t (TypeTag::Unassigned);
408482 }
409483}
410484
0 commit comments