jitcraft/API.cpp
changeset 64 11c81eb30246
parent 62 e04c5be84792
child 65 7c942b5adebc
     1.1 --- a/jitcraft/API.cpp	Sun Jul 08 16:49:17 2012 -0700
     1.2 +++ b/jitcraft/API.cpp	Sun Jul 08 17:57:44 2012 -0700
     1.3 @@ -74,8 +74,14 @@
     1.4      return *reinterpret_cast<To **>(*from);
     1.5  }
     1.6  
     1.7 +template <typename From, typename To> static inline To *
     1.8 +Open(From *from)
     1.9 +{
    1.10 +    return *reinterpret_cast<To **>(from);
    1.11 +}
    1.12 +
    1.13  template <typename From, typename To> static inline Ke::Local<To>
    1.14 -ToLocal(Handle<From> from)
    1.15 +ToLocal(From *from)
    1.16  {
    1.17      return Ke::Local<To>(reinterpret_cast<To *>(Ke::HandleScope::CreateHandle(from)));
    1.18  }
    1.19 @@ -192,3 +198,39 @@
    1.20  {
    1.21      ke::ZONE()->heap().reclaim();
    1.22  }
    1.23 +
    1.24 +unsigned
    1.25 +Ke::Module::numPublics()
    1.26 +{
    1.27 +    ke::Local<ke::Module> module(ke::ZONE(), Open<Ke::Module, ke::Module>(this));
    1.28 +    return module->publics()->length();
    1.29 +}
    1.30 +
    1.31 +Ke::Local<Ke::Function>
    1.32 +Ke::Module::getPublic(unsigned index)
    1.33 +{
    1.34 +    ke::Local<ke::Module> module(ke::ZONE(), Open<Ke::Module, ke::Module>(this));
    1.35 +    ke::Local<ke::Function> fun(ke::ZONE(), ke::Function::cast(module->publics()->at(index)));
    1.36 +    return ToLocal<ke::Function, Ke::Function>(fun);
    1.37 +}
    1.38 +
    1.39 +unsigned
    1.40 +Ke::String::length()
    1.41 +{
    1.42 +    ke::Local<ke::String> obj(ke::ZONE(), Open<Ke::String, ke::String>(this));
    1.43 +    return obj->length();
    1.44 +}
    1.45 +
    1.46 +const char *
    1.47 +Ke::String::chars()
    1.48 +{
    1.49 +    ke::Local<ke::String> obj(ke::ZONE(), Open<Ke::String, ke::String>(this));
    1.50 +    return obj->chars();
    1.51 +}
    1.52 +
    1.53 +Ke::Local<Ke::String>
    1.54 +Ke::Function::name()
    1.55 +{
    1.56 +    ke::Local<ke::Function> fun(ke::ZONE(), Open<Ke::Function, ke::Function>(this));
    1.57 +    return ToLocal<ke::String, Ke::String>(fun->name());
    1.58 +}