I'd like to use raylib with Terra/Lua (better metaprogramming) but the official examples only show how to interface with the C standard library, which I assume Terra is linked against already.
But raylib has a header (raylib.h, I know how to include it in terra) and a so/dll file (the actual code of the library).
How can I link my Terra cide against raylib?
P.S. I'm interested in writing mostly Terra and just doing macros in Lua which is the third use case listed on the Terra website:
A stand-alone low-level language. Terra was designed so that it can
run independently from Lua. In fact, if your final program doesn’t
need Lua, you can save Terra code into a .o file or executable. In
addition to ensuring a clean separation between high- and low-level
code, this design lets you use Terra as a stand-alone low-level
language. In this use-case, Lua serves as a powerful meta-programming
language. Here it serves as a replacement for C++ template
metaprogramming or C preprocessor X-Macros with better syntax and
nicer properties such as hygiene. Since Terra exists only as code
embedded in a Lua meta-program, features that are normally built into
low-level languages can be implemented as Lua libraries. This design
keeps the core of Terra simple, while enabling powerful behavior such
as conditional compilation, namespaces, templating, and even class
systems implemented as libraries.
Nevermind, I think I found what I need.
terralib.linklibrary(filename)
Load the dynamic library in file
filename. If header files imported with includec contain declarations
whose definitions are not linked into the executable in which Terra is
run, then it is necessary to dynamically load the definitions with
linklibrary. This situation arises when using external libraries with
the terra REPL/driver application.
Source: Terra docs
Related
I have a Lua module written in C compiled as a shared library, but when I use the module, editors cannot autocomplete it because they cannot see the content of the library.
In C, editors can deduce from the header files, how do you do that in Lua?
The Lua standard library does that but I can't figure out how. Every lua editor can tell me about standard library functions (their signature and documentation). How does it get this info from? How do I add such documentation to my own lua module?
It depends on editor you use. Each editor has own implementation, and you must check documentation how to extend autocomplete.
For notepad++ documentation about autocomplete:
https://npp-user-manual.org/docs/auto-completion/,
and file for this: Notepad++\autoCompletion\lua.xml
In one of the answers for a question on iOS Framework vs. Static Library, yoAlex5 quoted,
A Library is essentially a set of functions that you can call, these days usually organized into classes. Each call does some work and returns control to the client.
A Framework embodies some abstract design, with more behavior built in. In order to use it you need to insert your behavior into various places in the framework either by subclassing or by plugging in your own classes. The framework's code then calls your code at these points. The main control of the program is inverted, moved away from you to the framework. (Inversion of Control)
Could anyone please give any example for iOS with minimal code snippet where I can understand how Static Library cannot support inversion of control when a Framework can?
In the accepted answer to the question that you cited, the following is mentioned:
Hence on iOS, your only option is basically to use a static library or
static framework (the main difference being that a static framework is
distributed as a compiled .a file most often, whereas a static library
may simply be included as a subproject - you can see all of the code -
which is compiled first and its resulting .a file used as a dependency
by the project).
So the main difference on iOS actually is that normally a framework is used in compiled form, whereas a library is used as code. Therefore both support in principle inversion of control.
However, even if everything a framework can, could also be provided by a library, one should definitively restrict certain functionality to frameworks. Wiki says:
Frameworks have key distinguishing features that separate them from
normal libraries:
• inversion of control: In a framework, unlike in
libraries or in standard user applications, the overall program's flow
of control is not dictated by the caller, but by the framework.
• extensibility: A user can extend the framework – usually by
selective overriding – or programmers can add specialized user code to
provide specific functionality.
• non-modifiable framework code: The
framework code, in general, is not supposed to be modified, while
accepting user-implemented extensions. In other words, users can
extend the framework, but cannot modify its code.
I'd like to convert a CMake-based C++ library to bazel.
As part of the current CMake project, I'm using a libclang-based code generator that parses C++ headers and generates C++ code from the parsed AST. In order to do that, I need the actual compiler flags used to build the cc_library the header is part of. The flags are passed to the code generation tool so it can use clang's preprocessor.
Is there any way I could access the compiler flags used to build a dependency from a skylark- or gen_rule rule? I'm particularly interested in the include paths and defines.
We're working on it. Well, not right now, but will soon. You might want to subscribe to the corresponding issue, and maybe describe your requirements there so we take them into account when designing the API.
One feature I miss in Delphi (I hope it is at all possible) is that I cannot have Units automatically include their dependent units. This is possible in c++ headers.
For example, in c++:
dependentHeader.h:
#include "baseHeader.h"
Any headers included in baseHeader.h are available in dependentHeader.h. Another example is the precompiled header, whatever I include in the precompiled header is available to all header files in the project. This is very useful for including frequently used headers throughout a project.
Now back to Delphi:
I have a Unit called DebugService
In order to use it other units are required: DependentUnit1, DependentUnit2.
So in every Unit I use DebugService I have to manually add all the other dependent units: DependentUnit1, DependentUnit2.
What I want is just to be able to specify DebugService as a dependency and have all its dependencies come along?
So, in other words I want:
uses
DebugService;
and NOT:
uses
DebugService, DependentUnit1, DependentUnit2;
Is this at all possible?
Thank you!
Ironic that you would ask this, when a better question would be, "Why doesn't C++ have modules yet, in the year 2013".
Delphi's compilation units are not normally split into duplicate .h and .cpp files. You may have noticed that Delphi units have an Interface and Implementation section. This in turn becomes a true module system, compiled .DCU files differ significantly from C++/C compiler ".obj" files because just the interface area can be read, very quickly, by a compiler, when a "uses UnitX" is encountered.
Recently, CLANG/LLVM compiler developers at Apple started adding the rudiments of true module support to the latest CLANG/LLVM C and Objective-C compilers. This means that precompiled header support in XCode is no longer the preferred manner of doing things, because true modules are better than precompiled headers. You could say that a precompiled header system is like having one module, and only one module, as a shabby kludge that you are happy to have, when you cannot have the real thing, which is called Modules. You may say, you are a windows developer, what do you care about CLANG/LLVM? Just that it is evidence that the world is slowly giving up on precompilation, and moving eventually, to modules. The C++ standardization comittee, working at its current rate will certainly deliver you a working C++ standard (but not an implementation) by 2113, at the latest.
In short we might say your question might be asking, if the Horseless Carriage is going to gain features allowing it to accelerate the caching and rapid deployment of Oats to the Equine Power Units.
We don't need that here. We have a real compiler with real module support. End of story. You may notice that Modules (in clang/llvm) are faster than precompiled headers. They are also less of a source of problems, than precompiled headers which are a nearly endless source of crazy problems.
Pre-compiled headers don't have any semantic meaning that differs from standard headers. They are simply an optimisation to improve compilation times. Typically Delphi compilation much faster than C++ compilers and so the optimisation is not needed.
You cannot use unit A and transitively use all of unit A's dependencies. If you want to use definitions from a unit, it must be listed in the uses clause.
There is no equivalent to pre-compiled headers in Delphi. Adding the additional uses references is required if DebugService uses declarations from DependantUnit1 and DependentUnit2 in its own declarations of its interface section, and its declarations are then used by other units, thus they are dependant on those other units. If you can design your units to reduce interface dependencies, using dependent units only in the implementation section instead, then you won't have to include DependantUnit1 and DependantUnit2 in other units' uses clauses anymore. But I understand that is not always possible.
If you need to share code amongst multiple units, it is best to move that code to its own unit/package.
#include "baseHeader.h"
is equivalent to
{$I baseHeader.pas}
you can put anything you like into that file. Even the whole Interface section.
an other alternative to your problem is the use of conditional defines.
in main project file
{$DEFINE debugMyApp}
in each unit you use
use
abc
{$IFDEF debugMyApp}
, additionalUNit1
, additionalUNit2
, etc
{$ENDIF}
;
I have embedded Lua on Win32 in my project by means of statically linking it in (no, I can't switch to DLL). I would like to bundle more Lua extensions that use native code - not just pure .lua files. Specifically, I want to bundle Steve Donovan's winapi which comes as some lua files and some .c files.
How to do it?
You need to do two things. First, you have to compile the Lua DLL projects into non-DLL projects. Since they're intended to be DLL modules, they probably won't have provisions for this in their build systems. That means you have to do it yourself. Get rid of the DLL main functions and other specialized DLL functions (but take note of what they do and make sure you replicate it if it's important). And make sure that you change any #defines that try to include Lua with dynamic linking.
All Lua module DLLs export one or more functions of the form luaopen_*, where * is the name of the module to load. This function will likely be decorated with declspec() notation. Typically, the notation is done via a preprocessor macro, but it may not be. Either way, remove it, turning it into a normal function declaration.
Now, once you have created your lua_State object, just call that luaopen_* function with your lua_State.